Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program that meets the following requirements: Declare a method to

ID: 3618191 • Letter: W

Question

Write a Java program that meets the following requirements:

Declare a method to determine whether an integer is a primenumber

Use the following method declarations: public static BooleanisPrime (int num)

An integer greater than 1 is a prime number if its onlydivisor is 1 or itself. For example, isPrime (11) returnstrue, and isPrime (9) returns false.

Us the isPrime method to find the first thousand prime numbersand display every ten prime numbers in a row, as follows:

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 61 73 79 8389 97 … …

Important Notes: The input and output must use JOptionPanedialog and display boxes.

This is what I have so far:

import javax.swing.JOptionPane;


public class PrimeNumber {
public static void main(String[] args) {

String numStr;

do{
numStr = JOptionPane.showInputDialog(null, "Enter a number between1 and 1000");
if(numStr==null || numStr.trim().equals("")){
continue;
}
if("0".equals(numStr)){
break;
}
int input = Integer.parseInt(numStr);
if(input>0){
if(isPrime(input)){
JOptionPane.showMessageDialog(null, input + " is prime");
}else{
JOptionPane.showMessageDialog(null, input + " is not a prime");
}
}else{
JOptionPane.showMessageDialog(null, "Enter number >0");
}
}while(true);
} // end main()
public static boolean isPrime ( int num )
{
boolean prime = true;
int limit = (int) Math.sqrt ( num );

for ( int i = 2; i <= limit; i++ )
{
if ( num % i == 0 )
{
prime = false;
break;
}
}

return prime;
}

}

Declare a method to determine whether an integer is a primenumber

Use the following method declarations: public static BooleanisPrime (int num)

Explanation / Answer

please rate - thanks finds the primes between 1 and 1000 there is no input import javax.swing.JOptionPane; public class PrimeNumber { public static void main(String[] args) { String numStr="The Prime numbers between 1 and 1000 are "; int input,count=0; for(input=2;input
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote