0

a do-while loop!!! sorry

import java.io.*;
import java.util.*;

public class guessing
{
    
public static void main (String args[])
        {
            int answer = 22;
                
                System.out.print("Enter your guess, if you are correct you will be a winner  ");
                Scanner guessReader = new Scanner(System.in);
                int Input = guessReader.nextInt();
{  
                    if (Input< 1 || Input > 100)
                    System.out.print("your guess should be between 1 and 100!  ");
                    
                    else if (Input > answer)// creates the too high
                    System.out.print("your guess too high! ");
                    
                    else if (Input < answer) //creates too low
                    System.out.print("your guess too low! ");
                    
                    else
                    System.out.print("You are a winner!!");
                }
                

    }
}

Edited by dorotalp91: n/a

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by donaldw
0
boolean b = true;

do {
  ....
  //do something with the b variable
  ....
} while (b);

The loop will terminate when the answer is found.

Edited by javaAddict: n/a

-1
int Input ;
do
{
      System.out.print("Enter your guess, if you are correct you will be a winner  ");
      input = guessReader.nextInt();
      if (Input< 1 || Input > 100)
            System.out.print("your guess should be between 1 and 100! ");

       else if (Input > answer)// creates the too high
           System.out.print("your guess too high! ");

       else if (Input < answer) //creates too low
            System.out.print("your guess too low! ");
       else
            System.out.print("You are a winner!!");
}while(input != answer);

Edited by ejosiah: n/a

0

do

int Input = guessReader.nextInt();

                    if (Input< 1 || Input > 100)
                    System.out.print("your guess should be between 1 and 100!  ");
                    
                    else if (Input > answer)// creates the too high
                    System.out.print("your guess too high! ");
                    
                    else if (Input < answer) //creates too low
                    System.out.print("your guess too low! ");
                    
                    else
                    System.out.print("You are a winner!!");

while user input is not equal to the correct answer.


Take a stab at it, post your code and we'll help you fix your mistakes. DaniWeb isn't here to write your code for you.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.