我正在使用Scanner对象来获取用户输入,但是在输入后按下回车键后在控制台中,会创建一个新行。我只是希望它跳转到下一个输入区域而不是换行。下面是输出,之后是按Enter键后会发生的事情。
Please enter the number of residents in your house:
Please enter the area of the living space in square feet:
Please enter the Total monthly cost of internet:
Please enter the number of residents in your house: 5
Please enter the area of the living space in square feet:
Please enter the Total monthly cost of internet:
当程序读取输入时,我必须手动使用箭头键输入下一个。任何帮助表示赞赏。实际代码如下:
import java.util.Scanner;
//prints the House text-image
public class House{
public static void main(String[] args){
float monthlyInternet;
int numResidents, sqFeet;
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the number of residents in your house: ");
System.out.println("Please enter the area of the living space in square feet: ");
System.out.println("Please enter the Total monthly cost of internet: ");
numResidents = sc.nextInt();
sqFeet = sc.nextInt();
monthlyInternet = sc.nextFloat();
System.out.println(" . _ _ _ _ _ .");
System.out.println(" / \\ _ _ _ _ _ \\");
System.out.println(" | | 0 0 |");
System.out.println(" |_| _ _ H _ _ |");
}//end main
}//end class