:올바른 동안 루프 출력 (자바) 나는 지금 내 프로그램 출력이해야
단어를 입력 : 집
바꿀? : A는 집에서 아니요 없습니다
원하는 게 무엇 편지 은.
대체 할 편지는 무엇입니까? : b
집은 없습니다.
대체 할 편지는 무엇입니까? :
대체 할 편지는 무엇입니까? w
새 단어는 housw입니다.
_____________________________.
단어를 입력 : 여기
내 현재의 출력 집은 대체? 원하는 게 무엇 편지집에는 A가 없습니다
어떤 편지 교체 할 있나요? b
대체 할 편지는 무엇입니까?
____________________________________.
while 루프에 문제가 있습니다. 오류를 수정하는 방법을 모르겠습니다. 사람이 나던 당신이 그들을 그에게하고 새로운 문자를 선택하게 존재하는 문자를 입력하면 당신의 else 문에서
import java.util.Scanner;
public class WordScrambler {
//name
public static void main(String[] args) {
String word = "";
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a word: " + word);
word = keyboard.nextLine();
String readChar = null;
System.out.print("What letter do you want to replace?: ");
readChar = keyboard.next();
while(true)
{
if(word.contains(readChar))
{
String changeChar;
System.out.print("With what letter do you wish to replace it? ");
changeChar = keyboard.next();
System.out.println(word.replace(readChar, changeChar));
}
else
{
System.out.print("There is no "+ readChar + " in " + word);
System.out.println();
System.out.print("What letter do you want to replace?: ");
readChar = keyboard.next();
String changeChar;
System.out.print("With what letter do you wish to replace it? ");
changeChar = keyboard.next();
System.out.println(word.replace(readChar, changeChar));
}
}
}
}
우리는 당신을 위해 숙제를하고 있지 않습니다. 적절한 질문을하십시오. – VeenarM
어떤 오류가 발생하고 있습니까? 특정 질문을하십시오. – Chiseled
이것은 while 루프에는 문제가되지 않습니다. 귀하의 질문에 맞는 제목을 붙이시겠습니까? – khelwood