Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-04-2007, 08:11 AM
Senior Member
 
Join Date: Jun 2007
Posts: 114
Albert is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-04-2007, 08:16 AM
Member
 
Join Date: Jun 2007
Posts: 92
Daniel is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-04-2007, 08:19 AM
Member
 
Join Date: Jun 2007
Posts: 92
Marcus is on a distinguished road
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.

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"); } } }
Greetings

Marcus
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
while loop michcio New To Java 5 01-27-2008 01:56 AM
can you help me with this for loop? java_fun2007 New To Java 6 12-22-2007 11:20 AM
A loop that doesn't loop MichYer New To Java 2 07-30-2007 09:44 AM
While loop leebee New To Java 1 07-18-2007 04:11 PM
Loop Help HeavyD New To Java 5 07-10-2007 02:26 PM


All times are GMT +3. The time now is 10:05 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org