当它们被分开时,它们会合并

时间:2016-09-18 11:42:31

标签: java

所以我有我的代码编译但是当我运行它时它结合了我的行

System.out.print("Enter ID Number");
double ID=s.nextDouble();
if(ID >9999|| ID<0)
    ID=0;

System.out.print("Enter Make of Vehicle");
String make=s.nextLine();

System.out.print("Enter Model of Vehicle");
String model=s.nextLine();

System.out.print("Enter Color of Vehicle");
String color=s.nextLine();

System.out.print("Enter Year");
double year=s.nextDouble();
if(year <2000 || year>2017)
    year=0;

当我运行该程序时,它结合了线条来说明 enter make of vehicle enter model of vehicle 如何阻止它,因为它们应该是单独的条目

3 个答案:

答案 0 :(得分:0)

使用System.out.println代替System.out.print

答案 1 :(得分:0)

阅读双倍后放s.nextLine()。问题是s.nextDouble();不会消耗新的换行符,因此s.nextLine();自动调用System.out.println("Enter Make of Vehicle");之后,您再也看不到了,因为只有这一个换行符号(并且正在消费)。

double ID=s.nextDouble();
s.nextLine();
if(ID >9999|| ID<0)
    ID=0;

第二件事是用System.out.print替换System.out.println以在新行中打印输出。

答案 2 :(得分:0)

s.nextLine()之后致电double ID=s.nextDouble()nextDouble()消费\n

相关问题