Reputation: 11
this is probably a very simple correction that I cannot see but I'm pretty sure you guys can help me, this section of the code is supposed to read what the user inputs 1-12 (for a month of the year) and add one to the array location (i.e. if a user inputs 3 to the array then it will increment 'space' 2 in the array by one to tally the amount of occurences so to speak.), this code just goes through without any action taking place and gives the usual build successful after doing nothing.
anyway, I was hoping someone could give me a few pointers on where I'm going wrong.
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;
}
}
Upvotes: 0
Views: 144
Reputation:
In your main method you're not calling your method inputMonths(int[] months, Scanner input)
. So, your program won't do anything except creating the array and initialising the scanner. You have to add the call in your main method.
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int months [] = new int [12];
inputMonths(months, input)
}
Upvotes: 1
Reputation: 7820
You have to call your inputMonths
method in your main method... ;)
Upvotes: 9