Shavit

Ex. Bank #4

Nov 24th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1. // Shavit Borisov
  2. // HW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class PrimeNumber {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         Scanner in = new Scanner (System.in);
  12.        
  13.         int num;
  14.         boolean prime = true;
  15.        
  16.         System.out.print("Enter a number: ");
  17.         num = in.nextInt();
  18.        
  19.         for(int i = 2; i <= Math.sqrt(num); i++)
  20.         {
  21.             if((num % i) == 0)
  22.             {
  23.                 prime = false;
  24.                 break;
  25.             }
  26.         }
  27.         if(prime)
  28.             System.out.println("Your number is prime.");
  29.         else
  30.             System.out.println("Your number is composite.");
  31.        
  32.         in.close();
  33.     }
  34.  
  35. }
Add Comment
Please, Sign In to add comment