이 작업을 수행하는 동안 정확한 문자 수가 (140)에 도달 할 때까지 루프에서 모음을 삭제하지만 작동하지 않습니다. do while 루프가 작동하고 나서 조건이 충족되면 멈추는 지 확신 할 수 없지만 조건이 충족되면 나머지 코드를 어떻게 실행할 수 있습니까? 미리 감사드립니다.카운트가 작동하지 않을 때까지 문자를 삭제하려면 while 루프를 수행하십시오. Java
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter the phrase to be shortened: ");
String toCompress = scan.nextLine();
int length = toCompress.length();
System.out.println(length);;
do {
toCompress = toCompress.replaceAll("[AEIOUaeiou]", "");
}while(length >= 140);
System.out.println("Compressed phrase: ");
System.out.println(toCompress);
int length2 = toCompress.length();
System.out.print(length2);;
scan.close();
}
나는 작동하지 않는 것을 이해하지 못합니다. 프로그램을 실행할 때 어떤 결과가 나타 납니까? – Gendarme
[ "그러나 작동하지 않습니다"] (http://importblogkit.com/2015/07/does-not-work/)를 정의하십시오. – Pshemo
BTW :'string.replaceAll (target, replacement)'는'target'의 모든 항목을'replacement'로 대체하기 때문에 루프 안에서 처리하는 것은'replaceAll ("[AEIOUaeiou]", "")'모음 모음을 모두 즉시 바꿀 것이기 때문에. – Pshemo