Solved

check for negative integer

Posted on 2007-03-23
4
5,496 Views
Last Modified: 2008-02-20
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

thanks
J
0
Comment
Question by:jaggernat
4 Comments
 
LVL 20

Accepted Solution

by:
gatorvip earned 125 total points
ID: 18781252
umm..... if (your_variable < 0) .....

where your_variable is a numerical representation of your field
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 125 total points
ID: 18781332
int n = 0;
if ((n = Integer.parseInt(fieldValue)) < 0) {
    // problem
}
else {
    // no problem
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PDFBox - convert image to PDF, PDF resolution 3 115
custom annotations 9 29
servlet requestdispatcher include and forward differences 1 22
varialbe initialization 11 30
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now