我对Java有点陌生,我正在为单人作业学习它,我做了一条if语句,询问用户一系列事情,目前,我这样做是为了让用户输入对于高度和长度等于某些值,将输入的信息添加到数组中,但是当我在高度和长度中输入5和2时,它会重复并再次询问用户,我很确定这很简单但我有点卡住了哈哈
public void carInfo(standardSize standard) {
System.out.println("Please enter number plate: ");
input = new Scanner(System.in);
String plate = input.nextLine();
System.out.println("Please enter car make: ");
input = new Scanner(System.in);
String make = input.nextLine();
System.out.println("Please enter the height of your vehicle: ");
input = new Scanner(System.in);
int height = input.nextInt();
System.out.println("Please enter the length of your vehicle: ");
input = new Scanner(System.in);
int length = input.nextInt();
if (length == 0 || height == 0) {
System.out.println("cool one");
}
else if (length <= 2 && height >= 5) {
standard.setPlate(plate);
standard.setCarMake(make);
standard.setHeight(height);
standard.setLength(length);
addStandard();
System.out.println("working");
}
else {
System.out.println("done");
}
}
输入5的高度和2的长度后,它将再次要求用户输入车牌。