Advertisement
CamiloCastilla

Untitled

Nov 26th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.97 KB | None | 0 0
  1. package com.company;                                                                        
  2. import java.util.Scanner;                                                                    
  3. public class Main {                                                                          
  4.                                                                                              
  5.     public static void main(String[] args) {                                                
  6.         System.out.println("\nI have chosen a number from 1 to 10");                        
  7.         System.out.println("Your Guess:");                                                  
  8.         Scanner keyboard = new Scanner(System.in);                                          
  9.                                                                                              
  10.         int number= 7;                                                                      
  11.         int numberOfTries = 1;                                                              
  12.                                                                                              
  13.         while (numberOfTries < 10) {                                                        
  14.             int guess=keyboard.nextInt();                                                    
  15.             if (guess == number) { ;                                                        
  16.                 System.out.println("That is correct!");                                      
  17.                 System.out.println("It only took you " + numberOfTries + " tries");          
  18.                                                                                              
  19.             }                                                                                
  20.             else  {                                                                          
  21.                 System.out.println("That is not correct");                                  
  22.                 System.out.println("Please try again:");                                    
  23.             }                                                                                
  24.                                                                                              
  25.         numberOfTries ++;                                                                    
  26.         }                                                                                    
  27.                                                                                              
  28.                                                                                              
  29.                                                                                              
  30.     }                                                                                        
  31.                                                                                              
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement