当我运行代码时,我得到提示输入数字,然后输入数字,但之后没有任何反应!我试图在这里实现方法重载。任何帮助,将不胜感激。我的代码出错了?我试图实现方法重载
import java.util.Scanner;
public class MethodOverload {
public static void main(String [] args){
Scanner input = new Scanner(System.in);
Scanner inputDoub = new Scanner (System.in);
System.out.println ("Enter the int or double number");
int x = input.nextInt();
double y = inputDoub.nextDouble();
//int x;
//double y;
System.out.printf("Square of integer value %d", x, "is", square(x));
System.out.printf("Square of double value %f", y, "is", square(y));
}
public static int square(int intValue){
System.out.printf ("\nCalled square method with int argument: %d", intValue);
return intValue*intValue;
}
public static double square (double doubleValue){
System.out.printf ("\nCalled sqauer method with double argument: %d", doubleValue);
return doubleValue*doubleValue;
}
}
尝试使用一个'扫描仪'。此外,请参阅[这个线程](http://stackoverflow.com/questions/2912817/how-to-use-scanner-to-accept-only-valid-int-as-input)的例子使用'扫描仪'输入多个号码。 –