Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class exam2015q2
  3. {
  4. public static void main (String args[])
  5. {
  6. Scanner scan = new Scanner(System.in);
  7. System.out.println("Eneter a number");
  8. int num = scan.nextInt();
  9. int num1 = num-1;
  10. int count=0;
  11.  
  12. if(num%2==0)
  13. {
  14.  
  15. count++;
  16.  
  17.  
  18. System.out.println(+num+ " Is an even number");
  19. }
  20. else
  21. {
  22. System.out.println(num+" Is an odd number");
  23. }
  24.  
  25. boolean isPrime = true;
  26.  
  27. do{
  28.  
  29. if(num%num1==0)
  30. {
  31. isPrime = false;
  32. break;
  33. }
  34. num1--;
  35. }
  36. while(num1>=2);
  37. if(isPrime == true)
  38. {
  39. System.out.println(num +" is a prime number as it is only divisible by 1 and " +num);
  40. }
  41. else
  42. {
  43. System.out.println(num +" is NOT a prime number.It is divisible by " +count);
  44.  
  45.  
  46.  
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement