Prime Number List Use the isPrime method that you wrote in Programming Challenge 13 in a program that prompts the user to enter an integer number, then displays all prime numbers less than the user number separated by a space.     Here is a working code but please fix it so it will in Hypergrade which as all the test casses. I DO NOT NEED THANK YOU IN THE PROGRAM. IT HAS TO PASS ALL THE TEST CASSES PLEASE. THANK YOU!!!!!:   import java.util.Scanner; public class PrimeNumberList {         // Method to check if a number is prime     public static boolean isPrime(int num) {         if (num <= 1) {             return false;         }         for (int i = 2; i <= Math.sqrt(num); i++) {             if (num % i == 0) {                 return false;             }         }         return true;     }     public static void main(String[] args) {         Scanner scanner = new Scanner(System.in);                 // Prompt the user to enter a number         System.out.print("Enter a number: \n");         int userInput = scanner.nextInt();                 // Display prime numbers less than the user's number         System.out.print("Prime numbers are " + userInput + ": ");         for (int i = 2; i < userInput; i++) {             if (isPrime(i)) {                 System.out.print(i + " ");             }         }                 // Close the scanner         scanner.close();     } }   Test Case 1     Enter a number: \n 10ENTER 2 3 5 7    Test Case 2     Enter a number: \n 100ENTER 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter5: Making Decisions
Section: Chapter Questions
Problem 3GZ
icon
Related questions
Question
Prime Number List
Use the isPrime method that you wrote in Programming Challenge 13 in a program that prompts the user to enter an integer number, then displays all prime numbers less than the user number separated by a space.
 
 
Here is a working code but please fix it so it will in Hypergrade which as all the test casses. I DO NOT NEED THANK YOU IN THE PROGRAM. IT HAS TO PASS ALL THE TEST CASSES PLEASE. THANK YOU!!!!!:
 

import java.util.Scanner;

public class PrimeNumberList {
   
    // Method to check if a number is prime
    public static boolean isPrime(int num) {
        if (num <= 1) {
            return false;
        }
        for (int i = 2; i <= Math.sqrt(num); i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
       
        // Prompt the user to enter a number
        System.out.print("Enter a number: \n");
        int userInput = scanner.nextInt();
       
        // Display prime numbers less than the user's number
        System.out.print("Prime numbers are " + userInput + ": ");
        for (int i = 2; i < userInput; i++) {
            if (isPrime(i)) {
                System.out.print(i + " ");
            }
        }
       
        // Close the scanner
        scanner.close();
    }
}

 

Test Case 1

 
 
Enter a number: \n
10ENTER
2 3 5 7 
 

Test Case 2

 
 
Enter a number: \n
100ENTER
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Returning value from Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,