2017-05-16 8 views
-3

Javaを初めて使用しています。私と一緒に抱きしめてください。私は簡単なプログラムを試しています。犬の数は一定の点数に等しい。 4匹以上の犬は60点に等しい。Javaエラー:入力を解決できません。

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


     } 

} }すべてのヘルプは理解されるであろう。

+0

必ず、あなたはどのような問題に直面していますか? –

+0

結果が出力されず、エラーのみが解決されます。入力を解決できません。 – user7729282

+0

あなたがスキャナを 'input'ではなく' scan'と呼んでいるので、この 'input.nextInt();をこの' scan.nextInt(); 'に変更し、' int dogs = input.nextInt() ; 'これは 'dogs = scan.nextInt();' dogs'が既に定義されているためです。 –

答えて

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

    } 
} 

}

+0

が得られます。必要なのは 'int dogs = scan.nextInt();'だけです。 –

+0

これは、0の場合を除いて、「0点を獲得して5点を獲得しました」という2つの結果を出力する以外はトリックを行います。 – user7729282

+0

@RajithPemabanduケース0の後でブレークステートメントを忘れた – Raheel138

関連する問題