Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PrimeNumberB {
- public static void main(String[] args){
- Scanner input = new Scanner(System.in);
- int max;
- int min;
- int counter = 0;
- //Asking for input
- do {
- System.out.print("Enter a minimum value: ");
- min = input.nextInt();
- System.out.print("Enter a maximum value: ");
- max = input.nextInt();
- }
- while(min > max);
- input.close();
- int value = min;
- int number = value;
- //Prime or not
- if(max < 2) {
- System.out.println("No prime numbers");
- }else{
- System.out.println("Prime numbers from " + min + " to " + max + " are: ");
- }
- while(min <= max) {
- while(number >= 1) {
- if(value % number == 0) {
- counter = counter +1;
- }
- number= number - 1;
- }
- if(counter == 2) {
- System.out.println(value);
- }
- min++;
- }
- }
Add Comment
Please, Sign In to add comment