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!");
}
} }すべてのヘルプは理解されるであろう。
必ず、あなたはどのような問題に直面していますか? –
結果が出力されず、エラーのみが解決されます。入力を解決できません。 – user7729282
あなたがスキャナを 'input'ではなく' scan'と呼んでいるので、この 'input.nextInt();をこの' scan.nextInt(); 'に変更し、' int dogs = input.nextInt() ; 'これは 'dogs = scan.nextInt();' dogs'が既に定義されているためです。 –