Results 1 to 3 of 3
Thread: Problems with while loop
- 07-04-2007, 08:11 AM #1
Senior Member
- Join Date
- Jun 2007
- Posts
- 114
- Rep Power
- 0
Problems with while loop
Hello, I am currently trying to write a new program which enters a while loop waiting for s,g,l to be entered to e to exit the loop.
i have been trying to with no luck.
Any help of where to start what to declare, programming need.Using methods if that help
thanks!
Albert:rolleyes:
- 07-04-2007, 08:16 AM #2
Member
- Join Date
- Jun 2007
- Posts
- 91
- Rep Power
- 0
Well, what have you written so far? Do you need a full on tutorial or do you just need help in the while loop area?
Sun provides a great tutorial on java here:
To which they talk about while loops here:
While Loop
And talk about String Equals here:
String Comparison
We aren't going to do your assignment for you (as per the rules), but if you write something we can help you along the way.
And if you're not beginning just look a tthe while loop and String Equals part. That should help the most.
Greetings
Daniel:o
- 07-04-2007, 08:19 AM #3
Member
- Join Date
- Jun 2007
- Posts
- 92
- Rep Power
- 0
When you are comparing strings in java you need to use the comparison method equals. If you are comparing primitive data types then you would use !=, or ==.
So the program below is syntactically correct and will exit if you enter e. Not quite sure if this is logically correct from your description of what the program needs to do though.
Java Code:import javax.swing.*; public class Garden { static String product; int a,b,c,d; public static void main (String [] args ) { enterProduct(); System.exit(0); } public static void enterProduct() { product=JOptionPane.showInputDialog(null,"Enter e to exit"); while (!product.equals( "e" )) { product=JOptionPane.showInputDialog(null,"Enter e to exit"); } } }
Marcus:cool:
Similar Threads
-
Loop Help
By HeavyD in forum New To JavaReplies: 7Last Post: 09-22-2010, 10:55 PM -
while loop
By michcio in forum New To JavaReplies: 5Last Post: 01-27-2008, 01:56 AM -
can you help me with this for loop?
By java_fun2007 in forum New To JavaReplies: 6Last Post: 12-22-2007, 11:20 AM -
A loop that doesn't loop
By MichYer in forum New To JavaReplies: 2Last Post: 07-30-2007, 09:44 AM -
While loop
By leebee in forum New To JavaReplies: 1Last Post: 07-18-2007, 04:11 PM
Bookmarks