Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program that displays the prime numbers between 1 and 100 Input: None Output: The output should be all the prime numbers between

Write a Java program that displays the prime numbers between 1 and 100

Input: None

Output: The output should be all the prime numbers between 1 and 100. Each line of output will contain five prime numbers except for the last line

Create an algorithm (either flowchart or pseudocode) to use to write the program.

Code the program in Eclipse using a loop to calculate all prime numbers between 1 and 100. Use the code below to determine if a number is prime. Example of some of the lines of code in a working program are found below. Each line of output will contain 5 prime numbers except the last line.

// Assume the number is prime

boolean isPrime = true; // Is the current number prime?

// Test if number is prime

for (int divisor = 2; divisor <= number / 2; divisor++) { if (number % divisor == 0) { // If true, number is not

prime

isPrime = false; // Set isPrime to false break; // Exit the for loop

}

}

Program should display maximum of five numbers on each line.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions

Question

3. Identify the methods used within each of the three approaches.

Answered: 1 week ago