System.out.print("Please Select an Option...");
selected = (char) System.in.read();
}
while (selected < '1' || selected > '5'); // || => OR
//System.out.println("\n");
switch (selected)
{
case '1':
System.out.println("$: 6.08₺");
System.out.println("€: 6.88₺");
System.out.println("Gram Gold: 327₺");
System.out.println("Bitcoin/TL: 57.462₺");
System.out.println("Ripple/TL: 1.42₺");
break;
case '2':
System.out.print("Select Your Bank Account...");
**selectBankAccNum = (char) System.in.read();**
System.out.println(selectBankAccNum + " sd");
当外部开关盒为2时,我的程序正在打印选择您的...零件,但它不等待用户输入并完成运行。
答案 0 :(得分:2)
您要查找的是Scanner#next(),而不是System.in#read()。您需要使用InputStream创建一个Scanner对象,在本例中为System.in,因为它是实现InputStream的实现PrintStream。
Scanner scanner = new Scanner(System.in);
System.out.print("Please Select an Option...");
int selected = scanner.nextInt();
switch(selected) {
case 1:
//your code
break;
case 2:
System.out.print("Select Your Bank Account...");
int account = scanner.nextInt();
break;
}
答案 1 :(得分:1)
Scanner sc = new Scanner(System.in);
char c = sc.next().charAt(0);
使用此代码获取输入的字符