Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class exam2015q2
- {
- public static void main (String args[])
- {
- Scanner scan = new Scanner(System.in);
- System.out.println("Eneter a number");
- int num = scan.nextInt();
- int num1 = num-1;
- int count=0;
- if(num%2==0)
- {
- count++;
- System.out.println(+num+ " Is an even number");
- }
- else
- {
- System.out.println(num+" Is an odd number");
- }
- boolean isPrime = true;
- do{
- if(num%num1==0)
- {
- isPrime = false;
- break;
- }
- num1--;
- }
- while(num1>=2);
- if(isPrime == true)
- {
- System.out.println(num +" is a prime number as it is only divisible by 1 and " +num);
- }
- else
- {
- System.out.println(num +" is NOT a prime number.It is divisible by " +count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement