# Why is a negative percent not giving me the correct result?

• 10-25-2011, 10:05 PM
MXA92
Why is a negative percent not giving me the correct result?
When I input a negative number, it gives me an "E" when it should ask the user to enter a valid percentage, and I don't understand why :\
It works well with any positive integer :\....

Code:

import java.util.*;

{
public static void main (String[]args)
{
Scanner kybd = new Scanner(System.in);

int PERCENT = kybd.nextInt();

if (PERCENT >= 70)
{
System.out.println("A");
}
else if (PERCENT >= 60)
{
System.out.println("B");
}
else if (PERCENT >= 50)
{
System.out.println("C");
}
else if (PERCENT >= 40)
{
System.out.println("D");
}
else if (PERCENT >= 0)
{
System.out.println("E");
}
else if (PERCENT < 0)
{
}
}
}

• 10-25-2011, 10:25 PM
SFNYC
Re: Why is a negative percent not giving me the correct result?
It works for me:
Oh, and don't capitalize your variable names. By convention, capitalized variable names are reserved for constants.

Code:

import java.util.*;

{
public static void main (String[]args)
{
Scanner kybd = new Scanner(System.in);

int PERCENT = kybd.nextInt();

if (PERCENT >= 70)
{
System.out.println("A");
}
else if (PERCENT >= 60)
{
System.out.println("B");
}
else if (PERCENT >= 50)
{
System.out.println("C");
}
else if (PERCENT >= 40)
{
System.out.println("D");
}
else if (PERCENT >= 0)
{
System.out.println("E");
}
else if (PERCENT < 0)
{
}
}
}