在kb.nextInt()中找不到符号;

痛饼

我正在为我的课程编写一个程序,我想对其进行测试。但是,由于我在“ menuChoice = kb.nextInt();”处收到此错误“错误:找不到符号”,因此无法编译它。

import java.util.*;
public class Program3
{
public static void main (String [ ] args)
{
    Scanner kb = new Scanner(System.in);

    System.out.println("Please enter a non-negative integer.: ");
    int num = kb.nextInt();
    Random rand = new Random();
    int sum = 0;
    int factor = 1;
    int menuChoice;

    while (num > 0)
    {
        System.out.println("Number cannot be negative!  Please enter a non-negative integer.: ");
        num = kb.nextInt();
    }

    do
    {
        System.out.println("\nPlease choose an option:");
        System.out.println("\t0\tPrint the number");
        System.out.println("\t1\tDetermine if the number is odd or even");
        System.out.println("\t2\tFind the reciprocal of the number");
        System.out.println("\t3\tFind half of the number");
        System.out.println("\t4\tRaise the number to the power of 5 (using a Java method)");
        System.out.println("\t5\tRaise the number to the power of 5 (using a loop)");
        System.out.println("\t6\tGenerate 20 random numbers between 0 and the number (inclusive)");
        System.out.println("\t7\tFind the sum of 0 up to your number (using a loop)");
        System.out.println("\t8\tFind the factorial of the number (using a loop)");
        System.out.println("\t9\tFind the square root of the number (using a Java method)");
        System.out.println("\t10\tFind the square root of the number (using a loop, Extra Credit)");
        System.out.println("\t11\tDetermine whether the number is prime (using a loop, Extra Credit) ");
        System.out.println("\t12\tExit the program");

        menuChoice = kb.nextlnt(); //<<< error occurs right here!!!

        switch (menuChoice)
        {
            case 0: System.out.print("Your number is" + num);
                            break;
            case 1: if (num % 2 ==0)
                                System.out.print(num + " is even");
                            else
                                System.out.print(num + " is false");
                            break;
            case 2: if (num == 0)
                                System.out.print("There are no reciprocal");
                            else
                                System.out.print("The reciprocal of " + num + " is 1/" + num);
                            break;
            case 3: System.out.print("half of " + num + " is" + (num/2));
                            break;
            case 4: System.out.print(num + " of the power of 5 is" + (Math.pow(num , 5)));
                            break;
            case 5: for (int i = 1 ; i <= 6 ; i++)
                            for (int j = 1 ; j <= 6 ; j ++)
                                System.out.print(num + " of the power of 5 is" + ( i * j));
                            break;
            case 6: for (int i = 1 ; i<=20; i++)
                                System.out.println(rand.nextInt(6));
                            break;
            case 7: for (int i = 1; i <=num ; i++)
                                {
                                    sum += 1;
                                    System.out.println(sum);
                                }
                            break;
            case 8: for (int i = 1 ; i <=num; i++)
                                factor = factor*i;
                            System.out.println(factor);
                            break;
            case 9: double theSqrt = Math.sqrt(num);
                            System.out.println("The square root of " + num + " is " + theSqrt);
                            break;
            case 10:    System.out.println("Did not do this extra credit :(");
                                break;
            case 11:    boolean isPrime;
                                for (int i = 2; i<=num; i++)
                                {
                                    isPrime = true;
                                    for (int divisor = 2; divisor<Math.sqrt(num) && isPrime; divisor++)
                                    {
                                        if (num%divisor == 0)
                                            isPrime = false;
                                    }
                                    if (isPrime)
                                        System.out.println("The prime number of" + num + " is prime");
                                    }
                                break;
            case 12:    System.out.println("Exiting the now.");
                                break;
            default:        System.out.println("Illegal choice, try again");
                                break;
        }
    }while (menuChoice !=12);

 }
}

那是阻止我运行程序并查看我的代码是否正确编写的唯一部分。

感谢您的帮助。

杜格帕尔·辛格(Durgpal Singh)

你只要改变

menuChoice = kb.nextlnt();

menuChoice = kb.nextInt();

那么您的代码将正常运行。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

KB3185331和“系统找不到指定的文件”

来自分类Dev

在Windows累积更新中找不到修补程序的单个KB号

来自分类Dev

random.nextInt() 给我找不到符号

来自分类Dev

如何从存储值中删除(修剪)kB

来自分类Dev

Dumpsys meminfo:kB或KB?

来自分类Dev

在IText中添加图像时,PDF文件变为0 kb

来自分类Dev

从KB中添加两个int变量[Prolog]

来自分类Dev

在spacy实体链接中从kb id显示实体的描述

来自分类Dev

在R中解析150KB文本非常慢

来自分类Dev

如何从KB3001652更新挂起中恢复?

来自分类Dev

从KB中添加两个int变量[Prolog]

来自分类Dev

在IText中添加图像时,PDF文件变为0 kb

来自分类Dev

在umbraco中获取上传文件字段的上传KB/MB值

来自分类Dev

Windows更新KB4568831 / KB4562899破坏了IIS中托管的所有.NET应用程序

来自分类Dev

IntelliJ 14中的“找不到符号”

来自分类Dev

摆脱intelliJ中的“找不到符号”错误

来自分类Dev

在对象数组中找不到符号

来自分类Dev

在Android Studio中找不到符号类

来自分类Dev

在Junit测试中找不到符号失败

来自分类Dev

在Java中找不到符号时间

来自分类Dev

在Java中找不到符号SetUtils

来自分类Dev

R中的GSL库-找不到符号

来自分类Dev

错误:找不到Java中的异常符号

来自分类Dev

修复Java中找不到符号

来自分类Dev

在我的方法实例中找不到符号?

来自分类Dev

Android:在gdbserver中找不到调试符号

来自分类Dev

Java中的“找不到符号”错误

来自分类Dev

在 Antlr4 中找不到符号

来自分类Dev

在卡片类中找不到符号