Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shavit Borisov
- // HW
- import java.util.Scanner;
- public class PrimeNumber {
- public static void main(String[] args)
- {
- Scanner in = new Scanner (System.in);
- int num;
- boolean prime = true;
- System.out.print("Enter a number: ");
- num = in.nextInt();
- for(int i = 2; i <= Math.sqrt(num); i++)
- {
- if((num % i) == 0)
- {
- prime = false;
- break;
- }
- }
- if(prime)
- System.out.println("Your number is prime.");
- else
- System.out.println("Your number is composite.");
- in.close();
- }
- }
Add Comment
Please, Sign In to add comment