twitcode.org
 
back Pick the Lower Integer
Java
2012-02-05
Java_567


Pick the Lower Integer
Copy code copy code
  1. import java.util.Scanner;
  2. //@author javanshir
  3. public class PicktheLowerInteger {
  4.     public static void main(String[] args) {
  5.         int nmbr1 = (int)(Math.random()*10);
  6.         int nmbr2 = (int)(Math.random()*10);
  7.         int nmbr3 = (int)(Math.random()*10);
  8.  
  9.         if (nmbr1!=nmbr2 && nmbr2!=nmbr3 && nmbr1!=nmbr3){
  10.             System.out.print("What is the lowest of these three\n"+nmbr1+" "+nmbr2+" "+nmbr3+" ?\n");
  11.         }
  12.         Scanner input = new Scanner(System.in);
  13.         int answer = input.nextInt();
  14.        
  15.        
  16.         if(nmbr1>nmbr2)
  17.             if (nmbr3>nmbr2)
  18.                 if ( answer == nmbr2 )
  19.                 System.out.println("You are correct! The answer is "+nmbr2+" !");
  20.                 else System.out.println("You are wrong! The answer should be "+nmbr2+" !");
  21.            
  22.             else if ( answer == nmbr3 )
  23.                 System.out.println("You are correct! The answer is "+nmbr3+" !");
  24.                 else System.out.println("You are wrong! The answer should be "+nmbr3+" !");
  25.  
  26.         else if(nmbr1>nmbr3)
  27.             if ( answer == nmbr3 )
  28.                 System.out.println("You are correct! The answer is "+nmbr3+" !");
  29.                 else System.out.println("You are wrong! The answer should be "+nmbr3+" !");
  30.         else if ( answer == nmbr1 )
  31.                 System.out.println("You are correct! The answer is "+nmbr1+" !");
  32.                 else System.out.println("You are wrong! The answer should be "+nmbr1+" !");
  33.     }
  34.  
  35. }


Recent comments: ( 0 )


Please loggin to leave a comment!!