gpt4 book ai didi

java - 如何修复 “cannot find symbol error”?

转载 作者:行者123 更新时间:2023-12-02 11:09:13 24 4
gpt4 key购买 nike

我的代码“完整”,但是我遇到了以下错误:

"Cannot find symbol"


import java.util.*;
public class OrderNumbers
{
public static void main (String [] args)
{
Scanner scan = new Scanner(System.in);
int input1;
int input2;
int input3;

System.out.print("Enter the first number: ");
input1 = scan.nextInt();

System.out.print("Enter the second number: ");
input2 = scan.nextInt();

System.out.print("Enter the third number: ");
input3 = scan.nextInt();
}

{if ((input1 > input2 && input1 > input3))

{ if (input2 > input3)
{
System.out.print(input3 + "," + input2 + "," + input1);
}
else
System.out.print(input2 + "," + input3 + "," +input1);
}
else if ((input2 > input1 && input2 > input3))


{if (input1 > input3)
{
System.out.print(input3 + "," + input1 + "," + input2);
}
else
{
System.out.print(input1 + "," + input3 + "," + input2);
}
}
else if ((input3 > input1 && input3 > input2))

{if (input1 > input2)
{
System.out.print(input2 + "," + input1 + "," + input3);
}
else
System.out.print(input1 + "," + input2 + "," + input3);
}
else
{
System.out.println("ERROR!");

}
}
}

我已经阅读了很多论坛,似乎常见的问题是大多数人没有在正确的地方声明,但我确实相信我是。

最佳答案

在扫描程序语句之后,您还有多余的右括号来关闭main方法。

}   

{if ((input1 > input2 && input1 > input3))
删除这些 { },此问题将得到解决。

就是说, 格式化您的代码,如果 使用诸如Eclipse 之类的IDE则很容易。在此代码上使用Ctrl + Shift + F后,代码如下所示:
import java.util.*;

public class OrderNumbers {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int input1;
int input2;
int input3;

System.out.print("Enter the first number: ");
input1 = scan.nextInt();

System.out.print("Enter the second number: ");
input2 = scan.nextInt();

System.out.print("Enter the third number: ");
input3 = scan.nextInt();
}

{
if ((input1 > input2 && input1 > input3))

{
if (input2 > input3) {
System.out.print(input3 + "," + input2 + "," + input1);
} else
System.out.print(input2 + "," + input3 + "," + input1);
} else if ((input2 > input1 && input2 > input3))

{
if (input1 > input3) {
System.out.print(input3 + "," + input1 + "," + input2);
} else {
System.out.print(input1 + "," + input3 + "," + input2);
}
} else if ((input3 > input1 && input3 > input2))

{
if (input1 > input2) {
System.out.print(input2 + "," + input1 + "," + input3);
} else
System.out.print(input1 + "," + input2 + "," + input3);
} else {
System.out.println("ERROR!");

}
}
}
您是否看到格式化代码后问题更明显了?

关于java - 如何修复 “cannot find symbol error”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32463605/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com