Advertisement
KeeganT

Ch6Ex1a

Feb 21st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.45 KB | None | 0 0
  1. package ch6ex1a;
  2. import java.util.Scanner;
  3.  
  4. public class Ch6Ex1a
  5. {
  6.     public static void main(String[] args)
  7.     {
  8.         Scanner sc=new Scanner(System.in);
  9.         System.out.print("Enter a number: ");
  10.         int num=sc.nextInt();
  11.         boolean isPrime=true;
  12.         for(int c=num-1;c>1;c--)if(num%c==0)isPrime=false;
  13.         if(isPrime==true)System.out.println(num+" is prime.");
  14.         else System.out.println(num+" is not prime.");
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement