import java.util.Scanner;
public class Return {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
inputTest();
}
public static void inputTest(){
System.out.println("From Digit (9635)");
System.out.print("Enter a Digit: ");
int number = input.nextInt();
System.out.println(Digit(number));
}
public static int Digit(int number) {
if (number == 1) {
System.out.print("The 4th number in the argument is =\t");
return 5;
} else if (number == 2) {
System.out.print("The 3rd number in the argument is =\t");
return 3;
} else if (number == 3) {
System.out.print("The 2nd number in the argument is =\t");
return 6;
} else if (number == 4) {
System.out.print("The 1st number in the argument is =\t");
return 9;
} else {
System.out.print("Sorry! That's not part of the argument =\t");
**return 0;**
}
}
}
/*是否可以在同一個方法中使用(string,int)來得到一個 return(string)和return(int)? 我想這回0(INT)變成返回None(字符串)*/是否有可能在同一個方法中使用(string,int)來得到一個return(string)和return(int)?
Java方法只能有一個返回值。 –
這樣的問題和挑戰使我想到Ruby,Perl,Lua,Python等如何從函數返回項目列表。而且,從Java函數返回一個對象列表可以很好地解決這個問題,但會導致更多的工作處理結果。 – ChuckCottrill