Advertisement
Epi-Pdo

lab6_5

Nov 19th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package lab6_5;
  7.  
  8. /**
  9.  *
  10.  * @author Nyeh
  11.  */
  12. import java.util.Random;
  13. import java.util.Scanner;
  14. public class Lab6_5 {
  15.  
  16.     /**
  17.      * @param args the command line arguments
  18.      */
  19.     public static void main(String[] args) {
  20.         // TODO code application logic here
  21.         Scanner in=new Scanner(System.in);
  22.         Random r=new Random();
  23.         //the two random value
  24.         int ans;
  25.         int x,y;
  26.         int count=0;
  27.        
  28.        
  29.         System.out.println("Enter negative number to quit.");
  30.         x=r.nextInt(13);
  31.         y=r.nextInt(13);
  32.         System.out.print(x+" x "+y+" = ");
  33.         ans=in.nextInt();
  34.         if(compare(x,y,ans))
  35.             count++;
  36.            
  37.         while(ans>=0){
  38.         System.out.println("Enter negative number to quit.");
  39.         x=r.nextInt(13);
  40.         y=r.nextInt(13);
  41.         System.out.print(x+" x "+y+" = ");
  42.         ans=in.nextInt();
  43.         if(compare(x,y,ans))
  44.             count++;
  45.         }
  46.        
  47.         System.out.println("Your Score is :"+count);
  48.        
  49.     }
  50.    
  51.    
  52.     public static boolean compare(int a,int b,int c)
  53.     {
  54.        
  55.         if(a*b==c)
  56.             return true;
  57.         else
  58.             return false;
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement