Change program from a while loop to a do while loop

Assignment Help JAVA Programming
Reference no: EM131914397

Change program from a while loop to a do while loop.

import java.util.Random;

import java.util.Scanner;

import java.lang.System;

public class Game {


public static void main(String[] args){

System.out.println("Hello and welcome to my number guessing game.");

System.out.println("Pick a number: ");


Scanner inputnum = new Scanner(System.in);

int maxnum;

maxnum = inputnum.nextInt();


Random rand = new Random();

int number = rand.nextInt(maxnum);

int tries = 0;

Scanner input = new Scanner(System.in);

int guess;

boolean win = false;


while (win == false){


System.out.println("Guess a number between 1 and "+ maxnum +": ");

guess = input.nextInt();

tries++;

if (guess == number){

win = true;

}


else if(guess < number){

System.out.println("C'mon yourNumber is to low, tray again");


}


else if(guess > number){

System.out.println("Nope Number is to high, try again");


}


}


System.out.println("Way to go You win!");

System.out.println("It took you "+ tries + " tries.");


}

}

Reference no: EM131914397

Questions Cloud

What do you think the government should do : The website "Hot Air" thinks the government should not intervene in the menthol cigarette market: Once again, we have the federal government acting as nanny.
What you can infer his attitudes would be toward this : Do you believe that individuals in wealthier nations have responsibilities toward people in poorer countries?
Sample of fifteen students : A researcher has obtained the number of hours worked per week during the summer for a sample of fifteen students.
What is the monthly break-even point in unit sales : What is the monthly break-even point in unit sales and in dollar sales? What is the total contribution margin at the break-even point?
Change program from a while loop to a do while loop : Change program from a while loop to a do while loop - When I created the Game the user had to input a guess before going through the loop, with a Do-While Loop
What about text messaging-grooming and eating : Mike Hashimoto, assistant editorial page editor at the Dallas Morning News: I get as mad as the next person at the minivan driver cruising along 5 mph.
Test to find a mean difference : The standard deviation of the difference was 5 mmHg. What was the power of the test to find a mean difference of 2.5 mmHg at a = 0.05 (two-sided)?
What does professionalism in health care mean to you : Professionalism in Health Care. In your own words, what does "professionalism" in Health Care mean to you?
Should us government impose new rules to wear helmets : Should the U.S. government impose new rules requiring all bicyclists to wear helmets? New Zealand has enforced a national mandatory all-age bicycle helmet law.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd