我现在正在上Java入门课,对于我们的第一个程序之一,我们创建了一个程序来计算特许经营中不同商店的总销售额和销售额百分比。现在,当我输入变量的值时,光标从ex行的开头开始。
_Profits for shackA:(instead of here)下面是构成控制台界面的特定代码行:
double shackA, shackB, shackC;
System.out.print("Profits for Shack A: ");
shackA = scan.nextDouble();
System.out.print("Profits for Shack B: ");
shackB = scan.nextDouble();
System.out.print("Profits for Shack C: ");
shackC = scan.nextDouble();有没有办法修改开始位置以获得更清晰的输入?
发布于 2012-08-29 23:28:56
尝试替换
System.out.print("Profits for Shack A: ");使用
System.out.println("Profits for Shack A: ");发布于 2012-08-29 23:31:54
如果你可以切换到java.util.Console,你可以这样做:
Console cons = System.console();
String inputA = cons.readLine("Profits for Shack A: ");
shackA = Double.parseDouble(inputA);当然,您需要做一些错误处理来处理用户输入“ABCD!”的情况。而不是替身。
https://stackoverflow.com/questions/12181354
复制相似问题