Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 24 of 24

Thread: What's wrong with my code?? (it said cannot resolve symbol)

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What's wrong with my code?? (it said cannot resolve symbol)

    Here is my code:
    import java.util.*;

    public class Coin {

    public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    System.out.println("How many times you want to flip?");

    int time=input.nextInt();

    int array[]=new int[time];

    int showtime[]=new int[10];

    int head=0,tail=0,most=0;

    String output="";

    System.out.println("Generate: ");

    for (int x=0;x<time;x++) {

    int a=(int) (Math.random()*10+1);

    System.out.print(a+" , ");

    array[x]=a;

    showtime[a-1]++;

    if (a%2==0) head++;

    else tail++;

    }

    System.out.println();

    for (int x=0;x<10;x++) {

    System.out.println("No. \""+(x+1)+"\" showed "+showtime[x]+" time(s)");

    if (showtime[x]>showtime[most]) {

    most=x;

    output="The number(s) that showed up the most: "+(x+1);

    }
    else if (showtime[x]==showtime[most])

    output=output+" , "+(x+1);

    }

    System.out.println(output);

    if (head>tail) System.out.println("Heads came up the most");

    else if (head==tail) System.out.println("Heads=Tails");

    else System.out.println("Tails came up the most");

    }

    }
    What's wrong with my code??


  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    I just tested out the code using eclipse, and everything works fine for me! Check to see if there are any comments using strange symbols. Other than that, the code you posted is solid and works fine!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    Please post the full text of the error message.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    Error.jpg

    Here is the error message.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    Please post the full text here so parts can be selected for searches etc.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    Why can't it find the Scanner class?

    Try adding

    import java.util.Scanner;

  7. #7
    Junior Member
    Join Date
    Jun 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    Quote Originally Posted by javapenguin View Post
    Why can't it find the Scanner class?

    Try adding

    import java.util.Scanner;
    He has
     import java.util.*;
    though, and that should cover it.

  8. #8
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)



    It compiles for me as is.

  9. #9
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    Try adding import java.util.Scanner; anyway. If the Scanner class cannot be found for some reason, it will throw an error at the import statement. If that does happen, this is a problem with your environment.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    The OP has not said what is wrong with his code. What symbol is the problem?
    Don't we need that to be able to make suggestions?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    It is still not working. It said that cannot resolve the scanner class....

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    Please copy full text of error message and paste it here. Here is a sample:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    When I add "import java.util.Scanner;" it creates another error.... saying error on the Scanner class.....

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    Please post the full text of the compiler's error message.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    My error:

    flip.java:7: cannot resolve symbol
    symbol  : class Scanner
    location: class flip
                    Scanner input=new Scanner(System.in);
                    ^
    flip.java:7: cannot resolve symbol
    symbol  : class Scanner
    location: class flip
                    Scanner input=new Scanner(System.in);
                                      ^
    2 errors

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    What version of the JDK are you using? The Scanner class came with version 1.5
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    mine is 1.4.2. So what can I do??

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    Either rewrite the code to use classes available in version 1.4
    or download and install a newer version of the JDK.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Jun 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    I think some syntax problem can you send me complete coding which are using in your program.

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    @programmingtutorials The code as posted compiles with JDKs 1.5 and later.
    To see the OPs problem, try compiling the posted code with JDK 1.4
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    so, what can I do to replace the Scanner class in my 1.4.2 version?? How do I do it??

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    Start with System.in. Find a wrapper class to wrap it and that can be wrapped in the BufferedReader class.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Junior Member
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    Is there any examples?? Like how do I start? I forgot how to do a wrapper class

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: What's wrong with my code?? (it said cannot resolve symbol)

    Something like this:
    BuffferedReader br = new BufferedReader(new WrapperClass(System.in));

    You need to read the API doc to find what is the correct class for WrapperClass.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. fncharts plotting buy sell signal codes please resolve it
    By shankar4kv in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 8th, 2017, 02:05 AM
  2. what is wrong with this code???plz help me :(
    By kanikapant in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 17th, 2011, 06:03 PM
  3. equal symbol expected - where had I gone wrong?
    By tangara in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: September 14th, 2011, 09:01 PM
  4. what's wrong with my code
    By gcsekhar in forum Java Networking
    Replies: 2
    Last Post: July 19th, 2011, 09:31 AM
  5. Wrong code
    By whattheeff in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 4th, 2011, 05:30 PM