Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the following java script. I would like the result (line 21) to state List of primes before it prints the primes. And how

I have the following java script. I would like the result (line 21) to state "List of primes" before it prints the primes.

And how can I get the statement (line 22) to print on the next line after the result, when it runs the loop?

image text in transcribed

3 import java.util.*; 5 public class PrimeFactors public static void main (String args) Scanner reader new Scanner(System. in); System.out.print( Please enter an integer greater than 1 C0 to terminate): " 10 13 14 15 try long str = reader.nextLong(); if (str 1)1 20 21 primes(str); System. out.printlnC"Enter another integer greater than 1 ( to terminate):); 23 else if (str0) System. out.printlnC"Program terminated; break 25 27 28 // Makes sure the program catches strings as an error. Prints error message and clears Scanner catch (InputMi smatchException e) 30 31 32 System. out.println"Input is not an integer. Please enter an integer greater than 1 C0 to terminate): "); reader.nextLineO I while (true); reader.close); 35 37 38 39 public static void primes(long n) / Print the number of 2s that divide n while (r%2-=0) { 41 System.out.print(2+""); 45 46 47 48 / must be odd at this point. So we can skip one element (Note i- i +2) for (long 1-3; 1 Math.sqrt(n); 1+-2) { //While i divides n, printi and divide n while Cni0) System.out.print(i "); 50 51 52 53 //This condition is to handle the case when the integer is a prime number greater than2 if(n>2) 56 57 System.out.print(n); 59 AL Problems Declaration Console X PrimeFactors (1) [Java Application] /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/java (3. mar. 2018 14.08.54) Please enter an integer greater than 1 (0 to terminate): 9 3 Enter another integer greater than 1 (0 to terminate)

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

More Books

Students also viewed these Databases questions

Question

What is conflict?

Answered: 1 week ago

Question

Identify four applications of HRM to healthcare organizations.

Answered: 1 week ago