-6
import java.util.*;
public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        int x, y, sum;

        Scanner input = new input(system.in);

        input = parseInt32();


    }

}

这是一个例外:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    input cannot be resolved to a type
    input cannot be resolved to a type
    system cannot be resolved to a variable
    The method parseInt32() is undefined for the type Test

    at Test.main(Test.java:12)
4

2 回答 2

2

你需要使用nextInt();这样的东西:

public static void main(String[] args) {
    // TODO Auto-generated method stub


    System.out.println("First number: ");
    Scanner input = new Scanner(System.in);

    int x = input.nextInt(); 

    System.out.println("Second number: ");
    int y = input.nextInt();  

    int sum = x+y;

    System.out.println("Result: "+sum); 
}
于 2013-10-23T01:25:57.643 回答
1

Scanner input = new input(system.in); 应该是 Scanner input = new Scanner(System.in);

它给您一个错误,因为您试图将输入设置为 int 转换。它应该看起来像这样:

x = input.nextInt();

于 2013-10-23T01:24:37.083 回答