Question: How to program in Java: It turns out that cats are a lot smarter than the credit given to them. They have learned to send
How to program in Java:
It turns out that cats are a lot smarter than the credit given to them. They have learned to send simple encrypted messages to each other. These messages use a prime number as a key. Obviously, your cat doesn't want your dog to guess the key. This means your cat has to change the key at random times. However, being a cat, he's not very decisive about the number he wants. So, in exchange for not knocking your computer off your desk (he still gets to sit on your keyboard), he wants you to write a program that generates prime numbers. You will start off with 2, and generate the next prime number every time he presses the Enter key. Once he reaches a satisfactory prime number, he will hit '0', which is when you stop the program. Specifications This program is worth 50 points, and is called Primes.java. Create a class with the appropriate name. All of the code should be in the main method. (5 points) You should generate the prime numbers in order. (25 points) After printing a prime number, wait for user input. If the user presses Enter, generate the next prime number. Print a tab character after every prime number. If the user input were '0', stop the program. (15 points) Please include comments wherever appropriate. (5 points) Sample Runs Regular text is what's printed by your program. Underlined text is user input, shown here as a sample. You will not be printing the underlined parts in your program. Sample Run 2 3 5 7 11 13 17 19 23 29 lo le le le 10 10 18/3/2/2
Step by Step Solution
3.41 Rating (151 Votes )
There are 3 Steps involved in it
Java program that prints prime numbers until the user ends the program import ja... View full answer
Get step-by-step solutions from verified subject matter experts
