我有一个与Scanner工具有关的基本Java问题。 假设我有一个简单的程序,它接受用户输入并将其存储在变量中。 我的问题是,当我运行要求多个输入的程序时,光标会从问题的开头开始,而不是在后面。 我的代码如下:
public class question3 {
public static void main(String[] args){
Scanner s = new Scanner(System.in);
System.out.println("Enter the first number:");
Float a = s.nextFloat();
System.out.println("Enter the second number:");
Float b = s.nextFloat();
System.out.println("Sum = " + (a+b));
System.out.println("Difference = " + (a-b));
System.out.println("Product = " + (a*b));
}
}
当我运行这个程序时,它会看起来像输入第一个数字,然后我输入数字,接着是|输入第二个数字。"|"表示光标所在位置。当我输入时,它会显示在下面,但可能会让用户感到困惑,所以我想知道解决方案是什么。
这是一个IDE问题,因为代码没有其他问题。