![]()
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.


Note this "do while" is just a example of what I need to do with the "while" and "for" statements).
Reply With Quote


Bookmarks