简体   繁体   中英

How do I fix this "cannot find symbol error"?

My code is "complete" but I'm having trouble with the error:

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

  }
}
  }

I've read plenty of forums and it seems that the common issue is that most people are not declaring in the right space, but I do believe I am.

You have extra closing braces that close your main method after the scanner statements.

}   

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

Remove these { } and the problem will be fixed.


That said, format your code , which is easy if you use an IDE such as Eclipse . This is what your code looks like after using Ctrl+Shift+F on this code:

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

    }
  }
}

Do you see how much more obvious the problem is when your code is formatted?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM