arrays - Replacing a char value in a string (Java) -
in assignment need output:
enter word: house letter want replace?: e letter wish replace it? w new word housw.
_____________________________________________.
i got programme work code, need set while loops. here current code.
string word = ""; scanner keyboard = new scanner(system.in);
system.out.print("enter word: " + word); word = keyboard.nextline(); string readchar = null; system.out.print("what letter want replace?: "); readchar = keyboard.next(); string changechar; system.out.print("with letter wish replace it? "); changechar = keyboard.next(); keyboard.close(); system.out.println(word.replaceall(readchar, changechar)); system.out.println();
i need create programme output this:
enter word: house letter want replace?: a there no in house. letter want replace?: b there no in house. letter want replace?: e letter wish replace it? w new word housw.
how while loop portray output?
okay 1 possible way implement edited sec part of question:
public static void main(string[] args) { string word = ""; scanner keyboard = new scanner(system.in); system.out.print("enter word: " + word); word = keyboard.nextline(); boolean done = false; do{ string readchar = null; system.out.print("what letter want replace?: "); readchar = keyboard.next(); if(word.contains(readchar)){ string changechar; system.out.print("with letter wish replace it? "); changechar = keyboard.next(); done = true; keyboard.close(); system.out.println(word.replace(readchar, changechar)); } } while(!done); }
java arrays char
No comments:
Post a Comment