Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MainApp {
- public static void findOddAndPrimeNumbers(int low, int high) {
- for (int i = low; i <= high; i++) {
- if (i % 2 != 0) {
- if (isPrime(i)) {
- System.out.printf("%,d is both odd and prime.\n", i);
- } else {
- System.out.printf("%,d is just an odd number.\n", i);
- }
- } else {
- System.out.printf("%,d is an even number.\n", i);
- }
- }
- }
- public static boolean isPrime(int entry) {
- if (entry % 2 == 0) {
- return false;
- } else {
- for (int j = 3; j*j <= entry; j += 2) {
- if (entry % j == 0) {
- return false;
- }
- }
- }
- return true;
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int lowerLimit;
- int upperLimit;
- do {
- System.out.print("\nEnter a lower limit of range: ");
- lowerLimit = Integer.parseInt(sc.next());
- System.out.print("Enter a higher limit of range: ");
- upperLimit = Integer.parseInt(sc.next());
- } while (lowerLimit >= upperLimit);
- findOddAndPrimeNumbers(lowerLimit, upperLimit);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment