DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Need Help

Threaded View

  1. #1
    Join Date
    Feb 2006
    Posts
    14

    Need Help

    Hello to all:
    I need set up the java program for the "while statements" and the "for statements". I know how to do the "do while statements" as followsNote this "do while" is just a example of what I need to do with the "while" and "for" statements).

    import javax.swing.*; //shows path to newer swing classes
    import java.awt.*; //shows path to older AWT classes
    public class extends JFrame
    {
    public () // method name with same name as class.

    {
    int correctNumber = (int)(Math.random()*100+1);//comp picks number 1-100.
    int userAnswer =0; //userAnswer initialized to 0
    int tally = 1;// this is for the tally count.

    System.out.println("The random number generated was " + correctNumber);
    do
    {
    String guess = JOptionPane.showInputDialog
    ("Pick a number between 1 and 100 - your guess? ");
    userAnswer = Integer.parseInt(guess);
    if (userAnswer < 1 || userAnswer > 100)//sets the limit to the numbers between 1 and 100.

    }while (userAnswer != correctNumber);
    {// the curly brackets are needed because more than one statement for "if" are used.




    But I also need to set this same program with the "while" only statements and then I need to set another program for the "for" only statements. In other words what would I change in the "do while" statements so I can use the "while statements" and what would I change so I can use the "for statements" Any help. Thankyou.
    Last edited by Recency; 04-08-2006 at 09:59 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links