求教在以下代码的注释处的注释中的问题,应该怎么解决?谢谢!class func4
{    
    public static int getArea(int x,int y)
  {     
          return (x*y);
   }
  public static void main(String [] args)
    {   int temp;
       int x,y;
          int x=-5,y=6;   /*程序运行时要想从键盘输入x,y的值,应该怎么写 代码?                          */
           temp=getArea(x,y);
             B(temp,x,y);
             
    }public static void B(int temp,int x,int y)
 {
    
  if(x<=0||y<=0)
{ if((x*y)==0)
        {
          System.out.println("参数不能为0");
}
   else 
    {
      System.out.println("参数不能小于0");
    }
}
  else 
 {
  System.out.println(temp);
           System.out.println(x);
  System.out.println(y);
 }
 }
}

解决方案 »

  1.   

    import java.util.Scanner;
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    Java1.5之前使用
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String line = br.readLine();
    int x = Integer.parseInt(line);
    y如法炮制另外需要捕获异常,自己写吧。。
      

  2.   

    可以用String args[]来接收命令行中的参数..
      

  3.   

    在控制台输入
    public static void main(String[] args) throws IOException
    {
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      int x=Integer.parseInt(br.readLine());//输入x的值后回车
      ....
    }