-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayMonths1.java
More file actions
33 lines (28 loc) · 1.01 KB
/
ArrayMonths1.java
File metadata and controls
33 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Scanner;
public class ArrayMonths1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] months = {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
};
System.out.println("month: ");
String inputMonth = scanner.nextLine();
System.out.println("numzer: ");
int number = scanner.nextInt();
int currentMonthIndex = -1;
for (int i = 0; i < months.length; i++) {
if (months[i].equalsIgnoreCase(inputMonth)) {
currentMonthIndex = i;
break;
}
}
if (currentMonthIndex != -1) {
int resultIndex = (currentMonthIndex + number) % 12;
System.out.println(number + " months from " + inputMonth + months[resultIndex]);
} else {
System.out.println("nuh uh);
}
scanner.close();
}
}