Results 1 to 3 of 3
Thread: How Do I Say *This* In Java?
- 05-13-2008, 03:55 AM #1
Member
- Join Date
- May 2008
- Posts
- 1
- Rep Power
- 0
How Do I Say *This* In Java?
How do I say
if the variable called "example" does not equal an integer
DO
System.out.println("wrong");
ELSE
Do nothing;
I know that I shouldn't put an else in at all, but what about the IF statement?
and how do i say someting in a loop but one part of the sentence changes each time? like saying "you have entered the number for box 1" then after entering another integer it says "you have entered the number for box 2"?
thanks!Last edited by zythyl; 05-13-2008 at 04:14 AM.
- 05-13-2008, 04:25 AM #2
it would be nice if you try to design a method that has a parameter "String" and will return a boolean that represents true if the value receive is an integer or false otherwise.
What came first on mind is to put them on try/catch block.
then invoke that method likeJava Code:boolean isInteger(String test){ try{ Integer.parseInt(test); return true; }catch(Exception e){ return false; } }
Java Code:if(isInteger("7852862")) do something; else jump;Last edited by sukatoa; 05-13-2008 at 04:30 AM.
freedom exists in the world of ideas
- 05-13-2008, 04:38 AM #3
Pseudocode,and how do i say someting in a loop but one part of the sentence changes each time? like saying "you have entered the number for box 1" then after entering another integer it says "you have entered the number for box 2"?
Java Code:while( allowed ){ var = user's input if(isInteger(var)) System.out.printf("You've entered %s \n",var); else set not allowed; }freedom exists in the world of ideas


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks