我的程序需要扫描单个字符,直到“。”用户输入点。
然后打印出来,如下面的输出
THE OUTPUT
Hello! I print out an acronym.
Please, enter a character:
i
Please, enter a character:
d
Please, enter a character:
k
Please, enter a character:
.
i.d.k.
答案 0 :(得分:0)
试试这个,
import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
String input;
String output = "";
do{
System.out.println("Please Enter a Character");
input = s.nextLine();
output = output+"."+input;
}while(!input.equals("."));
System.out.println(output);
}
}
答案 1 :(得分:-1)
如果您想使用控制台使用:
System.out.print("Please, enter a character:"); //printing text to console
String input = System.console().readLine(); //reading the string
字符串转换的字符串:char c = input.charAt(0);
使用for循环使代码按照您的意愿运行:https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html