What is wrong with my if/else statement?
Code :
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.
Re: What is wrong with my if/else statement?
check the value of your income...
my output :
Code Java:
Are you an undergraduate student(y or n)? y
What is your income? 15001
income 0
You qualify for $1000 in financial aid.
Re: What is wrong with my if/else statement?
After I just changed a line and Parsed to int
my output:
Code Java:
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.
Re: What is wrong with my if/else statement?
Quote:
Originally Posted by
william
check the value of your income...
That is all you had to say...I saw it after you mentioned this.
Thanks