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

Thread: Help with this very simple error

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help with this very simple error

    //there is my code, all of it is correct accept i want the user to enter a random age and not have int set at 21. how can I make it so when i run the application the user enters their age and it will follow too the correct If statement.



    import javax.swing.*;
    public class Oldman
    {
    public static void main (String arg[] )
    {
    JOptionPane.showMessageDialog(null, "The Old Man says:");

    //Read in a value
    String enterNum = JOptionPane.showInputDialog(null, "What is your age?:");

    //convert string to a number
    double num1 = Double.parseDouble(enterNum);


    int user = 21;


    if (user <= 12) {
    JOptionPane.showMessageDialog(null, "Howdy youngster!");
    }
    else if (user >12 && user <20){
    JOptionPane.showMessageDialog(null, "Howdy, you're on your way!");

    }

    else if (user >=20 && user <40) {
    JOptionPane.showMessageDialog(null, "Howdy, you're a mover and a shaker!");

    }

    else if (user >=40){
    JOptionPane.showMessageDialog(null, "Howdy, old timer!");

    }


    }

    }


  2. #2
    Junior Member
    Join Date
    Feb 2012
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help with this very simple error

    please i wanna summit this quick

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help with this very simple error

    please this syntex needs to be solved

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

    Default Re: Help with this very simple error

    please i just need a guide on how to make the user input a number and have it go to the correct if statements.

  5. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help with this very simple error

    Can anybody help me with this?

  6. #6
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: Help with this very simple error

    Quote Originally Posted by Tctwins View Post
    please i just need a guide on how to make the user input a number and have it go to the correct if statements.
    Hi Tctwins,
    Why don't you simply use "num1" in your if statements instead of "user"? The variable "user" is unnecessary.

  7. The Following User Says Thank You to andreas90 For This Useful Post:

    Tctwins (February 21st, 2012)

  8. #7
    Junior Member
    Join Date
    Feb 2012
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help with this very simple error

    lol yeah im dumb. thanks dude =1 to u.

Similar Threads

  1. [SOLVED] Simple error that I can't figure out how to fix
    By javapenguin in forum What's Wrong With My Code?
    Replies: 8
    Last Post: July 11th, 2011, 08:27 AM
  2. Error for a simple array
    By DudeJericho in forum Collections and Generics
    Replies: 4
    Last Post: April 25th, 2011, 03:46 PM
  3. Has to be a simple error, but I can't find it.
    By fride360 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 22nd, 2011, 11:15 AM
  4. Simple error can't figure out.
    By n00bprogrammer in forum What's Wrong With My Code?
    Replies: 14
    Last Post: September 30th, 2010, 01:19 PM
  5. Error of data types and type casting in java program
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: September 2nd, 2009, 11:22 AM