好的,所以我想用特定输入替换用户返回的字符串。我想用'?'替换字符串中的每个小写字母,但不是空格!插入'?'的地方 should go 在 print 语句中,末尾带有随机空格(“”)。谢谢您的帮助。
import java.util.Scanner;
public class Program05 {
public static void main(String[] args)
{
Scanner scanner01 = new Scanner(System.in);
String inputPhrase;
do {
System.out.print("Enter a common phrase to begin!: ");
inputPhrase = scanner01.nextLine();
} while (!inputPhrase.matches("[a-z ]+"));
System.out.print("Press [ENTER] to continue...");
try
{
System.in.read();
System.in.skip(System.in.available());
} catch(Exception e){e.printStackTrace();} //though that was a neat little touch
do {
boolean valid = true;
for (int i = 0; i < inputPhrase.length(); i++)
{
System.out.println("Common Phrase\n-------------" + "\n" + " " );
}
//System.out.print(inputPhrase);
} while (!inputPhrase.matches("[a-z ]+"));
}
}