45A. Codecraft lll
Problem Link: https://codeforces.com/problemset/problem/45/A
Solution 1:
import java.util.Scanner;
public class A45 {
public static Scanner scn = new Scanner(System.in);
public static String[] str = { "January", "February", "March", "April", "May", "June", "July", "August",
"September", "October", "November", "December" };
public static int nextIdx(int currIdx, int change) {
return (currIdx + change) % 12;
}
public static int currIdx(String myStr) {
for (int i = 0; i < str.length; i++) {
if (myStr.equals(str[i]))
return i;
}
return -1;
}
public static void main(String[] argv) {
String str2 = scn.next();
int change = scn.nextInt();
int idx = currIdx(str2);
System.out.println(str[nextIdx(idx, change)]);
}
}
No comments:
Post a Comment
Thanks