为什么在while循环中出现这个numberformatexception?

rekjcdws  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(280)

试图得到“x”一个虽然循环终结者,但我相信它是错的。有人能帮忙吗?

import java.util.Scanner;

public class Bus {

    public static void main(String[] args) {
        int number_passanger = 0;
        int number_busstop = 0;
        final String stopcode = "X";
        String codeinput = "";

        while(!codeinput.equals (stopcode)) {
            number_busstop = number_busstop +1;

            codeinput = inputstring("How many passangers were on the bus?");
            number_passanger = number_passanger + Integer.parseInt(codeinput);
        }

        System.out.println("There were a total of " + number_passanger + "passangers on " + number_busstop + "buses.");

        System.exit(0);
    }

    public static String inputstring(String message) {
        Scanner scanner = new Scanner(System.in);
        String answer = scanner.nextLine();

        System.out.println(message);

        return answer;
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题