我如何解决此问题"无法找到符号错误"?

时间:2015-09-08 17:15:46

标签: java compiler-errors

我的代码是"完成"但是我遇到了错误:

  

"找不到符号"

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

  }
}
  }

我已经阅读了很多论坛,似乎常见的问题是大多数人并没有在合适的空间宣布,但我确实相信自己。

1 个答案:

答案 0 :(得分:1)

您有额外的结束括号,在扫描程序语句后关闭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!");

    }
  }
}

您认为在格式化代码时问题有多明显吗?