Guest User

Untitled

a guest
Jan 17th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. public class PrimeNumberB {
  2. public static void main(String[] args){
  3. Scanner input = new Scanner(System.in);
  4. int max;
  5. int min;
  6. int counter = 0;
  7.  
  8. //Asking for input
  9. do {
  10. System.out.print("Enter a minimum value: ");
  11. min = input.nextInt();
  12. System.out.print("Enter a maximum value: ");
  13. max = input.nextInt();
  14. }
  15. while(min > max);
  16. input.close();
  17.  
  18. int value = min;
  19. int number = value;
  20. //Prime or not
  21. if(max < 2) {
  22. System.out.println("No prime numbers");
  23. }else{
  24. System.out.println("Prime numbers from " + min + " to " + max + " are: ");
  25. }
  26. while(min <= max) {
  27. while(number >= 1) {
  28. if(value % number == 0) {
  29. counter = counter +1;
  30. }
  31. number= number - 1;
  32. }
  33. if(counter == 2) {
  34. System.out.println(value);
  35. }
  36. min++;
  37. }
  38. }
Add Comment
Please, Sign In to add comment