1. ホーム
  2. java

[解決済み] Java エラー。入力が解決できません

2022-02-09 09:50:39

質問

私は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!");


        }

} } ご協力をお願いします。

解決方法は?

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!");

    }
}

}