Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Julia Lamar
- //2-10-16
- //Prime Checker
- import java.util.*;
- public class PrimeChecker
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- System.out.print("Print a number: ");
- int num = inputInt();
- int counter = 0;
- //loop ---- depend on the number the user gives
- for (int i = 2; i < num; i++) {
- if (num % i == 0)
- counter++;
- }//endloop
- if (num < 2)
- System.out.println("Please insert a number larger than 1");
- else if (counter > 0)
- System.out.println(num +" is not prime!");
- else
- System.out.println(num +" is prime!");
- }//closemain
- }//closeclass
- game plan:
- accumulator: total = 0;
- total < total + i
- counter
- mod = 0
Add Comment
Please, Sign In to add comment