Java错误:输入无法解析

时间:2017-05-16 00:11:22

标签: java switch-statement case

我是Java新手。请多多包涵。我正在尝试一个简单的程序。狗的数量等于一定数量的积分。 4只或更多只狗等于60分。

import java.util.Scanner;
public class Welcome {

public static void main(String[] args){
    int dogs,points; 

    Scanner scan = new Scanner(System.in);
    System.out.println("Enter the number of dogs: ");
    int dogs = input.nextInt();

    switch (dogs)
    {
    case 0:
        System.out.println("You've earned 0 points!");
    case 1:
        System.out.println("You've earned 5 points!");
        break;
    case 2:
        System.out.println("You've earned 15 points!");
        break;

    default: System.out.println("You've earned 60 points!");


        }

} } 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:-1)

import java.util.Scanner;

public class Welcome {

public static void main(String[] args) {
    int dogs;

    Scanner scan = new Scanner(System.in);
    System.out.println("Enter the number of dogs: ");
    dogs = scan.nextInt();

    switch (dogs) {
        case 0:
            System.out.println("You've earned 0 points!");
            break;
        case 1:
            System.out.println("You've earned 5 points!");
            break;
        case 2:
            System.out.println("You've earned 15 points!");
            break;
        case 3:
            System.out.println("You've earned 30 points!");
            break;
        case 4:
            System.out.println("You've earned 60 points!");
            break;

        default:
            System.out.println("You've earned 60 points!");

    }
}

}