Hello, my code seems to work, but the last condition is always false. I've tried every month and the output seems to be right but it still doesn't work.
Can someone help me?
package de.codegym.task.task09.task0922;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/*
Welches Datum ist heute?
*/
public class Solution {
public static char[] replace(int charactersToReplace, char[] chars, String replacement) {
char[] result = new char[chars.length - charactersToReplace + replacement.length()];
char[] replacementChars = replacement.toCharArray();
System.arraycopy(replacementChars, 0, result, 0, replacement.length());
int j = charactersToReplace;
for (int i = replacement.length(); i < result.length; i++) {
result[i] = chars[j];
j++;
}
return result;
}
public static void main(String[] args) throws Exception {
//schreib hier deinen Code
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String input = reader.readLine();
Date date = df.parse(input);
df = new SimpleDateFormat("MMM dd, yyyy");
String dateString = df.format(date);
char[] chars = findAndChangeMonthInString(dateString);
//System.out.println(dateString);
for (char c : chars) {
System.out.print(c);
}
}
public static char[] findAndChangeMonthInString(String s) {
char[] chars = s.toCharArray();
List<String> searchedMonths = Arrays.asList("Jan.", "Feb.", "März", "Apr.", "Mai", "Juni", "Juli", "Aug.",
"Sept.", "Okt.", "Nov.", "Dez.");
List<String> months = Arrays.asList("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV",
"DEC");
String month;
for (int i = 0; i < searchedMonths.size(); i++) {
month = searchedMonths.get(i);
String replacement = months.get(i);
char[] current = month.toCharArray();
if (s.startsWith(month)) {
return replace(current.length, chars, replacement);
}
}
return chars;
}
}
don't ask me why because I don't know why but I should probably change something about that) (Oh wait forget about that I'll fix it (Thomas said it but I read your comment first)).