check for negative integer

hi guys
i think this is easy..

I have a field where users can enter a number, but the number must be a positive integer
like 10, 20 ect . i want to check if the number is negative  
something like

if(the integer is negative or starts with a minus '-' sign)

System.out.println("Please enter positive integer only"); //display this in console

any ideas how i can do that in java

LVL 10
Who is Participating?
gatorvipConnect With a Mentor Commented:
umm..... if (your_variable < 0) .....

where your_variable is a numerical representation of your field
CEHJConnect With a Mentor Commented:
int n = 0;
if ((n = Integer.parseInt(fieldValue)) < 0) {
    // problem
else {
    // no problem
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.