Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我试图使用用户输入来重复Java程序_Java_Loops_For Loop_While Loop_User Input - Fatal编程技术网

我试图使用用户输入来重复Java程序

我试图使用用户输入来重复Java程序,java,loops,for-loop,while-loop,user-input,Java,Loops,For Loop,While Loop,User Input,我一直在制作一个程序,允许用户输入他们的汽车的品牌、型号和年份来显示它。在我询问用户是否想继续之前,程序会执行它应该执行的操作。无论我键入是或否,都不会发生任何事情 我的代码如下: cmis242wk1包 导入java.util.Scanner 公车{ public int year_made;//您的车辆年份 public String car_make;//您的车辆品牌,例如:本田 public String car_model;//您的车辆型号EX:CIVIC public YourVeh

我一直在制作一个程序,允许用户输入他们的汽车的品牌、型号和年份来显示它。在我询问用户是否想继续之前,程序会执行它应该执行的操作。无论我键入是或否,都不会发生任何事情

我的代码如下: cmis242wk1包

导入java.util.Scanner

公车{ public int year_made;//您的车辆年份 public String car_make;//您的车辆品牌,例如:本田 public String car_model;//您的车辆型号EX:CIVIC

public YourVehicle () {
    Scanner scanint = new Scanner(System.in);
    System.out.print("Input your year make and model of your car with spaces in between");
    year_made=scanint.nextInt();
    car_make=scanint.nextLine();
    car_model=scanint.nextLine();
}
    
    public void display() {
        System.out.println("I own a " + year_made + car_make  + car_model);
        
        Scanner scanint = new Scanner(System.in);
        Scanner ans1 = new Scanner(System.in);
        System.out.println("If you want to upgrade input a new year");
        
        year_made=scanint.nextInt();
        System.out.println("I now am the owner of a new " + year_made + car_make  + car_model);
        System.out.println();
        
        String ans = new String();
        
    
        System.out.println("If you wish to continue type yes if not type no");
        ans1.nextLine();
        while(true)
        if (ans.equals("no")) { 
            System.out.println("Program Done");
            break;
        }
        else
            if (ans.equals("yes")) {
            System.out.println("We shall continue");
            ans1.nextLine();
        }
        }
    
}

要在下面运行的代码: cmis242wk1包

公营车辆{

public static void main(String args[]) {
    YourVehicle calc=new YourVehicle();
            calc.display(); ;
}
}

有没有关于如何解决这个问题的建议?
谢谢。

这是否回答了您的问题?您希望所有必须重复的代码都在循环内部,而不是外部。请修复代码的格式。要么用三个回记号换行,要么全部缩进四个空格。字符串ans=new String();两者都不等于是或不是