Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- System.out.println("\nI have chosen a number from 1 to 10");
- System.out.println("Your Guess:");
- Scanner keyboard = new Scanner(System.in);
- int number= 7;
- int numberOfTries = 1;
- while (numberOfTries < 10) {
- int guess=keyboard.nextInt();
- if (guess == number) { ;
- System.out.println("That is correct!");
- System.out.println("It only took you " + numberOfTries + " tries");
- }
- else {
- System.out.println("That is not correct");
- System.out.println("Please try again:");
- }
- numberOfTries ++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement