永发信息网

用java怎么从键盘读入?

答案:3  悬赏:80  手机版
解决时间 2021-04-26 08:40
  • 提问者网友:雾里闻花香
  • 2021-04-26 05:31
比如要求输入a,b两个数然后比较大小怎么做?用eclipse写。
最佳答案
  • 五星知识达人网友:北城痞子
  • 2021-04-26 05:40

Scanner input = new Scanner(System.in);//使用scanner类


int a = input.nextInt();


int b=input.nextInt();


剩下的就是比较了

全部回答
  • 1楼网友:患得患失的劫
  • 2021-04-26 07:32

import java.util.Scanner;

public class Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("请输入第一个数:"); int num1 = input.nextInt(); System.out.print("请输入第二个数:"); int num2 = input.nextInt(); if(num1>num2){ System.out.println("较大的数为:"+num1); }else if(num1<num2){ System.out.println("较大的数为:"+num2); }else{ System.out.println("两个数相等"); } } }

  • 2楼网友:往事隔山水
  • 2021-04-26 07:07

public class soso{ public static String newstring(String str) { //把传进来的str 进行拆分 以“ ”空格拆分 String[] st = str.split(" "); //定一个接受新的字符串 String newstring = ""; //倒着处理字符串 for(int i=st.length-1;i>=0;i--) { //倒着一个一个的把字保存 for(int num = st[i].length()-1;num>=0;num--) { newstring=newstring+st[i].charAt(num); } //处理完以后 加一个空格 newstring=newstring+" "; } return newstring; } public static void main(String args[]){ // 定义一个接受输入进来的字符串 String str="";

BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); try { System.out.println("请输入被转换的内容:"); //接受字符串 str = in.readLine(); //打印方法返回的字符串 System.out.println(newstring(str)); } catch (IOException e) { e.printStackTrace(); } } }

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯