Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a Java program that implements the following state diagram. Turn in a listing of your program, and the results of a test run with
Write a Java program that implements the following state diagram. Turn in a listing of your program, and the results of a test run with n = 97. You will need to know how to do input in Java. Use the following construct and include the given class in your program.
readNumber update entry -reado exit otPrime true [n != 01/ i )notPrime = false handleZero checkPrime doDivide exit / notPrime = true [i > notPrime) writeResult [notPrime writeYes entry/ write(prime") InotPri writeNo entry/writenot prime") int n = (new IntReader()).readInt();
import java.io.*;
// a class to read in an integer
public class IntReader{
private LineNumberReader d;
public IntReader(){
d = new LineNumberReader(new BufferedReader(new
InputStreamReader(System.in)));
} // end of constructor
public int readInt(){
try{
return(Integer.parseInt(d.readLine()));
}catch(Exception e){}
return(Integer.MAX_VALUE);
} // end of readInt
} // end of class IntReader
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