这可能是一个非常简单的修正,我看不到,但我很确定你们可以帮助我,这部分代码应该读取用户输入1-12(一年中的一个月)和加一个到数组的位置(即,如果用户输入3到数组中,那么它将增加数组中的'空间'2来计算出现的数量),这个代码只是经过而没有采取任何行动放置并且在无所事事之后给平常的构建带来成功。为什么这种方法不能工作?
无论如何,我希望有人能给我一些指导我哪里出错的地方。
import java.util.Scanner;
public class BirthMonth {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int months [] = new int [12];
}
public static int[] inputMonths(int[] months, Scanner input){
System.out.println("please enter the first month with a birthday:");
int month = input.nextInt();
months[month - 1] ++;
//arr[i] = Input.nextInt();
while (month != -1){
System.out.println("please enter the next month to be tallied");
month = input.nextInt();
months[month - 1] ++;
}
return months;
}
}
修辞问题:'java.util.Scanner'只能用于作业练习吗?有没有人真的用过它的东西? – skaffman 2011-04-13 14:19:26
...所以你意识到你需要在你的主要方法中调用inputMonths,对吗? – ryebr3ad 2011-04-13 14:19:41
你的缩进在修复之前很奇怪,你应该确保你的缩进一致,你的代码会更容易阅读。 – Blorgbeard 2011-04-13 14:21:57