Results 1 to 15 of 15
Thread: Java Error Check
- 05-08-2012, 08:16 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
- 05-08-2012, 08:27 PM #2
Senior Member
- Join Date
- Feb 2012
- Posts
- 117
- Rep Power
- 0
Re: Java Error Check
Where do you want the validation to occur? While they type? When they hit enter?
First, we have to know if a number is odd. How do you know if a number is odd?
Second, how do you get input from a JOptionPane?
Third, how do you use that input? What kind of checks would you perform on it to see if it's odd?
- 05-08-2012, 08:40 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
Re: Java Error Check
I want the validation to occur once the user hits enter.
To check if a number is odd (I THINK....) I could use
The way I was going to get input from a JOption Pane was going to be:Java Code:if (var1 % 2 != 0) //Then the number is odd
If the number is not odd, I want display an error message (I know I would use a do-while loop for this), if the number is odd, I want to pass var1 to a different module, and continue with the code.Java Code:var1= Integer.valueOf(JOptionPane.showInputDialog("Enter an odd number"));
- 05-08-2012, 08:41 PM #4
Senior Member
- Join Date
- Feb 2012
- Posts
- 117
- Rep Power
- 0
Re: Java Error Check
Sounds like you have everything you need. What's the issue then?
- 05-08-2012, 08:47 PM #5
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
Re: Java Error Check
My java compiler doesn't like the "%" sign?
- 05-08-2012, 08:49 PM #6
Senior Member
- Join Date
- Feb 2012
- Posts
- 117
- Rep Power
- 0
Re: Java Error Check
Post your code. Use code tags.
- 05-08-2012, 08:52 PM #7
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
Re: Java Error Check
This is the statement I am working with (or trying to make work)
Java Code:{ String var1; do{var1 = Integer.valueOf(JOptionPane.showInputDialog("Enter an odd number")); if (var1 % 2 == 0){ JOptionPane.showMessageDialog(null, "Please enter an odd number!"); }else{ Advance(var1); } }while (var1 % 2 != 0); }
- 05-08-2012, 08:54 PM #8
Senior Member
- Join Date
- Feb 2012
- Posts
- 117
- Rep Power
- 0
Re: Java Error Check
Are you sure var1 is an integer? What's the remainder of a String?
- 05-08-2012, 08:57 PM #9
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
Re: Java Error Check
I could be totally wrong in saying this, but I thought that input into the JOptionPane had to be input as a string and then converted to what type you actually needed it
- 05-08-2012, 09:00 PM #10
Senior Member
- Join Date
- Feb 2012
- Posts
- 117
- Rep Power
- 0
- 05-08-2012, 09:08 PM #11
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
Re: Java Error Check
Ah Hah! One more issue I am running into...with the code from my post 7. If an even number is entered, it is giving me the message to "Enter an odd number" like it should, but then it is leaving the program, I want it to loop back up and ask me to again input an odd number.
- 05-08-2012, 09:12 PM #12
Senior Member
- Join Date
- Feb 2012
- Posts
- 117
- Rep Power
- 0
Re: Java Error Check
}while (var1 % 2 != 0);
Does this say "do the above while var1 is even"? Or does it say "Do the above while var1 is odd"?
- 05-08-2012, 09:19 PM #13
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
Re: Java Error Check
It says to do the above code while var1 is odd. Which means I should flip it to read:
Java Code:var1 % 2 == 0
Last edited by Rahim2312; 05-08-2012 at 09:24 PM.
- 05-08-2012, 09:20 PM #14
Senior Member
- Join Date
- Feb 2012
- Posts
- 117
- Rep Power
- 0
Re: Java Error Check
What is the error case? Should it repeat the question if var1 is odd?
- 05-08-2012, 09:28 PM #15
Member
- Join Date
- Apr 2012
- Posts
- 88
- Rep Power
- 0
Similar Threads
-
'Check For Updates' gives an error when installing
By Muskar in forum EclipseReplies: 1Last Post: 03-03-2011, 08:37 PM -
Pls check why my code is giving a runtime error
By Beginner in forum New To JavaReplies: 3Last Post: 05-26-2010, 12:32 AM -
You have an error in your SQL syntax; check the manual that corresponds to your MySQL
By habibiwalla in forum JDBCReplies: 2Last Post: 08-31-2009, 02:50 PM -
how to check java
By funkygarzon in forum New To JavaReplies: 10Last Post: 03-08-2009, 08:39 AM -
CRC check program 1 error
By javakid9000 in forum New To JavaReplies: 1Last Post: 03-19-2008, 05:04 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks