好了,我正在学习Java中的方法,我必须调用一个方法10次才能显示10个不同的单词(我已经有了for循环来调用这个方法)。我只是想不出怎么让它有10个不同的单词。这就是我到目前为止所拥有的。我讨厌这么多的求助,但我已经被难住了一天多了。
public static void tenWords(int display){
}
public static void main(String[] args) {
for(int i=0;i<10;i++){
tenWords(i);
}
}发布于 2011-12-18 06:31:22
试一试:
public class Main{
private static String[] words = new String[] {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
public static void tenWords(int display){
System.out.println(words[display]);
}
public static void main(String[] args) {
for(int i=0;i<10;i++){
tenWords(i);
}
}
}冰
发布于 2011-12-18 06:29:07
没有给出完整的答案,因为这看起来像一个家庭作业//学习问题?
从可取到不可取:
发布于 2013-08-05 02:35:15
您可以通过使用任何循环来反复调用main方法(您的偏好),但我使用if语句来调用main方法。以下是我的示例代码:将此代码用作reference..you会发现它很方便:
import java.util.Scanner;
public class NewTest {
public static void main(String[] args) {
Scanner src = new Scanner(System.in);
System.out.println("Enter the Value:");
int a = src.nextInt();
char result;
if (a >= 90) {
result = 'A';
}
else if (a >= 80) {
result = 'B';
}
else if (a >= 70) {
result = 'C';
}
else if (a >= 60) {
result = 'D';
}
else {
result = 'F';
}
if(result == 0){
System.out.println("Do Nothing");
}
else{
NewTest i = new NewTest();
if(i!= null){
System.out.println(result);
}
//Here it goes to the main method again and runs it.
i.main(args);
}
}
}希望这对你有用...:)
https://stackoverflow.com/questions/8548333
复制相似问题