Hi I'm learning java, I'm doing a program where I talk about the birthdays of 5 people on days of the year (I only take the 365 days I do not take into account leap years) but I'm stuck I have the days and months in two arrays after I use those two pieces of information that the user previously put in to take out the day of the year but I want to store them in a new array since I will use it later to use a sort with that array, this is my code
import java.util.Arrays; import java.util.Scanner;
public class birthday { private static Scanner input;
public static void main(String args[]){
int[] num2 = {31,59,90,120,151,181,212,243,273,304,334,365};
int value = 2;
input = new Scanner(System.in);
String[] words = new String[value];
int[] month = new int [value];
int [] num = new int[value];
for (int x = 0; x < value; x++) {
System.out.println("Enter a name");
words[x] = input.next();
System.out.println(Arrays.toString(words));
System.out.println("Birth month?(1 to 12) ");
month[x] = input.nextInt();
System.out.println(Arrays.toString(month));
System.out.println("day of the month(1 to 31) ");
num[x] = input.nextInt();
System.out.println(Arrays.toString(num));
int month1 = month[x];
int day = num[x];
int sumDays;
if (month1==1) {
sumDays = day;
}else {
sumDays = num2[month1-1-1] + day;
}
System.out.println("the day of the birthday is " + sumDays);
{
}
}
}
}
As you see, ask for name month and day, then use month and day to get the day of the year and at the end give an output
Enter a name
juan
[juan, null]
Birth month?(1 to 12)
8
[8, 0]
day of the month(1 to 31)
14
[14, 0]
dia de cumple es 226
and at the end I want to put that 226 in an array jutno with the remaining 4, thanks for your help