Question
In java code, A prime number is an integer that is evenly divisible only by 1 and itself. For example, the only integers that divide
In java code,
A prime number is an integer that is evenly divisible only by 1 and itself. For example, the only integers that divide 7 evenly are 1 and 7, thus 7 is a prime number. On the other hand, a number that is not prime is said to be composite. An integer n is composite if there exist integers a and b such that n = ab, with 1 < a < n, and 1 < b < n. For example, the number 24 is composite since it can be factored in the following ways: 24 = 2 X 12, 24 = 3 X 8, and 24 = 4 X 6, with other factorizations possible, including 24 = 1 X 24 (but not only this way). Write a method named isPrime, which takes an integer as an argument and returns true if the argument is prime or false otherwise. Write a driver program with a main method that calls the isPrime method to demonstrate that it works. Finally, modify your program so that it makes use of the isPrime method to store a list of all the prime numbers from 1 to 100 in a text file. The list should look like the following: 2 3 5 . . . 97
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started