当前位置: 代码迷 >> Java相关 >> 刚刚学JAVA的菜鸟问过问题
  详细解决方案

刚刚学JAVA的菜鸟问过问题

热度:133   发布时间:2012-03-10 14:35:53.0
刚刚学JAVA的菜鸟问过问题
import java.io.*;
public class cacluate {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
     int a,b,c;
     System.out.print("请输入a:");
     try{
         BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
         String inputLine=in.readLine();
         a=Integer.valueOf(inputLine).intValue();
     }catch(Exception exc){System.out.println("用户输入错误!");
     return;
     }
     System.out.print("请输入b:");
     try{
         BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
         String inputLine=in.readLine();
         b=Integer.valueOf(inputLine).intValue();
     }catch(Exception exc){System.out.println("用户输入错误!");
     return;
     }
     if(a>b)
          c=a;
     System.out.println(c);
     
    }
}
为什么最后一个输出语句会有错误,,,不懂,,,,另外求一名高人指点一下我JAVA,,,,QQ329956247可以帮我的家一下我,感激不尽
搜索更多相关的解决方案: class  void  public  return  import  

----------------解决方案--------------------------------------------------------
c没有被初始化,因为你的  if(a>b) c=a;限定了只有a>b时,才会给a赋值,所以当a<=b时,c不会被赋值,所以会报错。可以定义 int a,b;  int c=0;
----------------解决方案--------------------------------------------------------
回复 2楼 liuyujieny
为什么我赋值了C的初始值,但是程序还是无法运行?
----------------解决方案--------------------------------------------------------
回复 3楼 yuyuehan2010
你把你改的程序发给我看看,不会啊可以运行
----------------解决方案--------------------------------------------------------
   ____________初始化后可以正常运行啊
----------------解决方案--------------------------------------------------------
初始化后明明可以正常运行啊
----------------解决方案--------------------------------------------------------
这是怎么个情况
----------------解决方案--------------------------------------------------------
  相关解决方案