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 4 of 4

Thread: Problem with my code, help would be appreciated.

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with my code, help would be appreciated.

    so here is the code fragment

    private int getChoice(int lower, int upper) {
    System.out.println("--------------------------------------------------------------");
    System.out.println("Please enter your choice: ");
    String userSelection = Keyboard.readInput();
    Integer.parseInt(userSelection);
    if (userSelection >= lower && userSelection <= upper){
    return userSelection;
    }else{
    displayMainMenu();
    }

    the problem is ">="

    where it says "bad operand types for binary operator '>=' "

    first type: java.lang.string
    second type: int

    Integer.parseInt(userSelection); this line is supossed to turn the string to an int and now im super confused.

    thanks in advance


  2. #2
    Junior Member
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem with my code, help would be appreciated.

    Integer.parseInt(userSelection) returns an integer. you must create an int variable and store it, or simply paste the same code where userSelection is in the if statement

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

    Default Re: Problem with my code, help would be appreciated.

    The binary operator: >= can not be used to compare a String to an int. One solution would be to convert the String to an int and then compare two int values.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Problem with my code, help would be appreciated.

    yeah thank you guys i got it to work

Similar Threads

  1. All help would be much appreciated!!
    By Rkelly155 in forum What's Wrong With My Code?
    Replies: 13
    Last Post: April 13th, 2012, 05:38 AM
  2. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 08:36 AM
  3. Help really appreciated
    By Thermal_Vent in forum Java Theory & Questions
    Replies: 1
    Last Post: November 15th, 2010, 08:42 AM
  4. any help is much appreciated
    By Schmitz14 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 8th, 2009, 07:51 PM
  5. Need a little help. would be greatly appreciated
    By ryan29121 in forum Java Theory & Questions
    Replies: 4
    Last Post: September 27th, 2009, 02:03 PM