In fact, I'm trying to replace the number with words in a sentence that the user gives. The date format of this event; For example: My birthday is on 16/6/2000 and I'm newbie to the java→ become --->My birthday is on sixteenth july two thousand and I'm newbie to the java
Here is the code:
Scanner reader = new Scanner(System.in);
System.out.println("Enter any numbers: ");
String nom = reader.nextLine();
if(nom.contains("/")){
String parts[] = nom.split("[/]");
String part1 = parts[0];
String day[] = part1.split("\\s+");
String get_day = day[day.length -1];
String get_month = parts[1];
String part3 = parts[2];
String year[] = part3.split("\\s+");
String get_year = year[0];
String s = NumberConvert.convert(Integer.parseInt(get_day)) +
NumberConvert.convert(Integer.parseInt(get_month)) +
NumberConvert.convert(Integer.parseInt(get_year));
String con = nom.replaceAll("[0-9].*/[0-9].*/[0-].*", s);
System.out.println(con);
} else {....}
But I got the result:
My birthday is on sixteenth july two thousand
How to solve it. In fact, I want to get the value before and after the "/" slash and convert it to words and replace it as the user's original input.
I tried:
String con = nom.replaceAll("[0-9].*/[0-9].*/[0-9999]", s);
But the result will look like this:
My birthday is on sixteenth july two thousand 000 and I'm newbie to the java
//after two thousand index "000" is appearing
source
share