사실 저는 number를 사용자가주는 문장의 단어로 대체하려고합니다. 이 사건 날짜 형식; 예를 들어 : My birthday is on 16/6/2000 and I'm newbie to the java
은 ->이 될 --->My birthday is on sixteenth july two thousand and I'm newbie to the java
여기번호를 Java의 올바른 위치에있는 단어로 바꿉니다.
코드입니다 :
Scanner reader = new Scanner(System.in);
System.out.println("Enter any numbers: ");
String nom = reader.nextLine(); // get input from user
//checking contains that has "/" or not
if(nom.contains("/")){
String parts[] = nom.split("[/]");
String part1 = parts[0]; //data before "/" will be stored in the first array
String day[] = part1.split("\\s+");// split between space
String get_day = day[day.length -1];// get last array
String get_month = parts[1]; //data in the between of "/" will be stored in the second array
String part3 = parts[2]; // data after "/" will be stored in the third array
String year[] = part3.split("\\s+");// split between space
String get_year = year[0];// get first array
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); // replace number to word
System.out.println(con); // print the data already converted
} else {....}
하지만 내가 가진 한 결과는 다음과 같습니다
My birthday is on sixteenth july two thousand
//"and I'm newbie to the java" is disappear [How to solve it]//
방법 그것을 해결하십시오. 실제로 나는 "/"슬래시의 전후에 가치를 얻고 그것을 단어로 변환하고 그것을 사용자로부터의 원래 입력으로 대체하려고합니다.
String con = nom.replaceAll("[0-9].*/[0-9].*/[0-9999]", s); // a bit change [0-9].* to [0-9999]
그러나 출력은 다음과 같이된다 :
내가 시도한 것은
이My birthday is on sixteenth july two thousand 000 and I'm newbie to the java
//after two thousand index "000" is appearing
숫자 나 날짜를? – aksappy