日期:2014-05-20 浏览次数:20810 次
import java.util.Scanner;楼主你的Scanner用法不对,先通过new Scanner(System.in);创建的是对象a和b,然后再通过new出来的对象调用其中的方法来获取用户输入值。
public class At18_1 {
public static void main(String[] args) {
Scanner a=new Scanner(System.in);
Scanner b=new Scanner(System.in);
int num1;
int num2;
System.out.println("请输入num1的值:");
num1=a.nextInt();
System.out.println("请输入num2的值:");
num2=b.nextInt();
double c=num1*num1+num2*num2;
System.out.println(c);
}
}
public static void main(String[] args) {
Scanner a = new Scanner(System.in);
Scanner b = new Scanner(System.in);
int num1 = 0;
int num2 = 0;
System.out.println("请输入num1的值:");
num1 = a.nextInt();
System.out.println("请输入num2的值:");
num2 = b.nextInt();
double c = num1 * num1 + num2 * num2;
System.out.println(c);
a.close();
b.close();
}