當我運行代碼時,我得到提示輸入數字,然後輸入數字,但之後沒有任何反應!我試圖在這裏實現方法重載。任何幫助,將不勝感激。我的代碼出錯了?我試圖實現方法重載
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)的例子使用'掃描儀'輸入多個號碼。 –