java的输入、输出编程

来源:百度知道 编辑:UC知道 时间:2024/07/04 10:06:28
您好!下面是问题:
java:
由键盘输入3个整数,输出其中最大的三个数,
怎么编写啊????
我自己是这样写的,可是却编译出错,您帮我看看!

import java.io.*;
class Import1{
public static void main(String args[]) {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入一个整数:");
String str=br.readLine( );
int i=Integer.parseInt(str);
System.out.println("请输入一个整数:");
String str=br.readLine( );
int f=Integer.parseInt(str);
System.out.println("请输入一个整数:");
String str=br.readLine( );
int g=Integer.paseInt(str);
int result;
if(i>g&&i>f) result i;
if(g>i&&g>f) result g;
if(f>i&&f>g) result f;
System.out.println("result="+result);
}
}
请您给出正确的程序,并指出我的错误,谢谢了!(请回复)

错误
1.重复定义str。String str 定义一次即可,str就可重复使用。
2.paseInt(str); 拼写错误。正确为:parseInt(str);
3.result没有初始化。正确为:int result = 0;
4.没有异常处理。正确为:public static void main(String args[]) throws IOException
5.result = i。。。你没写赋值符号

修改后的代码如下,不过不提倡你以后这么写程序,看看q85340813的代码,简洁明快。
///////////////////////////////////////////
import java.io.*;

class Import1 {
public static void main(String args[]) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入一个整数:");
String str=br.readLine( );
int i=Integer.parseInt(str);
System.out.println("请输入一个整数:");
str=br.readLine( );
int f=Integer.parseInt(str);
System.out.println("请输入一个整数:");
str=br.readLine( );
int g=Integer.parseInt(str);
int result = 0;
if(i>g&&i>f) result=i;
if(g>i&&g>f) result=g;
if(f>i&&f>g) resul