Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class PrimeGenerator
- {
- private int n;
- private int a;
- private int b;
- public PrimeGenerator(int number)
- {
- n = number;
- }
- public void primeNumber()
- {
- while (n > 1)
- {
- n = n-1;
- a = n-1;
- boolean check = false;
- while (!check && a != 0)
- {
- if (n%a == 0)
- {
- check = true;
- }
- else
- {
- a = a-1;
- }
- if (a == 1)
- {
- System.out.println(n);
- check = true;
- }
- }
- }
- }
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- System.out.println("Please enter an integer: ");
- PrimeGenerator nick = new PrimeGenerator(in.nextInt());
- nick.primeNumber();
- }
- }
Add Comment
Please, Sign In to add comment