这个java程序还能否再简略点?

来源:百度知道 编辑:UC知道 时间:2024/06/03 12:47:48
import java.io.*;
public class maxNumbler
{
public static InputStreamReader inreader=new InputStreamReader(System.in);
public static BufferedReader breader=new BufferedReader(inreader);
public static float readFloat()throws Exception
{
String str;
System.out.println("输入实数,以换行结束");
str=breader.readLine();
str=str.trim();
return Float.parseFloat(str);
}
public static void main(String args[]) throws Exception
{
float x,y,max;
x=readFloat();
y=readFloat();
if(x<y)
max=y;
else
max=x;
System.out.println("max="+max);

}
}
程序目的是从键盘输入两个数,判断大小后输出大的数.请给出更简略的程序

//超精简程序,绝对能正确运行
public class maxNumbler {
public static void main(String[] args) throws Exception{
java.util.Scanner sc = new java.util.Scanner(System.in);
System.out.println("输入两个数求最大值,每输入一个以回车键结束:");
System.out.println("Max="+Math.max(sc.nextFloat(),sc.nextFloat()));}}

public static void main(String args[]) throws Exception {
Scanner s = Scanner(System.in);
float x = s.nextFloat();
float y = s.nextFloat() ;
System.out.println(x>=y?x:y);
}

一楼的写的很简单了
呵呵

class max{
public static void main(String args[]){
int x=Integer.parseInt(args[0]);
int y=Integer.parseInt(args[1]);
System.out.println(Math.max(x,y));
}
}
这个直接采用命令行参数,
编译javac max.java
运行 java max 12 45
输出结果 45