再问题(Y / N)

时间:2017-10-20 14:25:36

标签: java

我正在制作一个关于车辆特性的项目。我有代码让它运行一次没有任何问题。但是,在我输入Y再次执行后,它会将前两个问题放在一个提示中。我该如何解决这个问题?

public static void main(String[] args) {

    //break continue
    char choice;

    Scanner in = new Scanner(System.in);

    do{       
        //vehicle make
        System.out.print("Please enter vehicle make ");
        String make = in.nextLine();

        //vehicle model
        System.out.print("Please enter vehicle model ");
        String model = in.nextLine();

        //vehicle color
        System.out.print("Please enter color of vehicle ");
        String color = in.nextLine();

        //number of doors
        System.out.print("Please enter number of doors ");
        int door = in.nextInt();

        //Print out information
        System.out.println("Your vehicle is a " +make + " " +model + ", which is " +color + " with " +door + " doors.");

        //Continue prompt
        System.out.print("Do you want to continue (Y/N): ");
        choice=in.next().charAt(0);

        }while((choice!='n')&&(choice!='N'));      

    } //end main

} //end class

0 个答案:

没有答案