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: What is wrong with my if/else statement?

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Location
    Texas
    Posts
    20
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default What is wrong with my if/else statement?

    public static void main(String[] args) 
        {
     
           int income = 0;
           char answer;
           String student, input;
     
           Scanner keyboard = new Scanner (System.in);
     
            System.out.print("Are you an undergraduate student(y or n)? ");
            input = keyboard.next();
            answer = input.charAt(0);
     
            if( answer == 'y' || answer == 'Y')
            {
                System.out.print("What is your income? ");
                student = keyboard.next();
     
                if( income <= 15000 )
                {
                    System.out.println("\nYou qualify for $1000 in financial aid.\n");
                }
                else if (income > 15000)
                {
                    System.out.println("\nYou qualify for $500 in financial aid.");
                }
     
            }
            else if( answer == 'n' || answer == 'N')
            {
                System.out.println("\nYou do not qualify for financial aid.\n");   
            }
     
     
     
     
        }

    I cannot get it to print "You qualify for $500 in financial aid" if income is greater than $15,000.


  2. #2
    Member
    Join Date
    Jun 2011
    Location
    Rhode Island
    Posts
    69
    My Mood
    Bored
    Thanks
    11
    Thanked 7 Times in 6 Posts

    Default Re: What is wrong with my if/else statement?

    check the value of your income...

    my output :

    Are you an undergraduate student(y or n)? y
    What is your income? 15001
    income 0
     
    You qualify for $1000 in financial aid.

  3. The Following User Says Thank You to william For This Useful Post:

    CSUTD (October 24th, 2011)

  4. #3
    Member
    Join Date
    Jun 2011
    Location
    Rhode Island
    Posts
    69
    My Mood
    Bored
    Thanks
    11
    Thanked 7 Times in 6 Posts

    Default Re: What is wrong with my if/else statement?

    After I just changed a line and Parsed to int

    my output:
    Are you an undergraduate student(y or n)? y
    What is your income? 15001
    income 15001
     
    You qualify for $500 in financial aid.
    BUILD SUCCESSFUL (total time: 6 seconds)

    it works then.

  5. #4
    Junior Member
    Join Date
    Oct 2011
    Location
    Texas
    Posts
    20
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: What is wrong with my if/else statement?

    Quote Originally Posted by william View Post
    check the value of your income...
    That is all you had to say...I saw it after you mentioned this.

    Thanks

Similar Threads

  1. not a statement?
    By frozen java in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 23rd, 2011, 08:57 PM
  2. If statement help
    By Legion of Daughters in forum Loops & Control Statements
    Replies: 12
    Last Post: September 6th, 2011, 08:25 AM
  3. whats wrong with my if statement
    By semicolon in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 23rd, 2011, 04:28 PM
  4. what is wrong with my return statement??????
    By amr in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 13th, 2010, 07:55 PM
  5. If-Else Statement help
    By SnowCrashed in forum Loops & Control Statements
    Replies: 5
    Last Post: February 9th, 2010, 07:57 PM