Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, Having a heck of a time getting started with this one? Can anyone provide so

ID: 3640414 • Letter: H

Question

Hi,

Having a heck of a time getting started with this one? Can anyone provide solution?
Thank you!

Write a program that reads in a single column of integers (from file) from a file (which I will supply). The name of the file containing the integers will be given at run-time as a command line argument. Your program will read in each number and determine if its even or odd and if it is prime. Write your results to a file in this format:
N is EVEN (ODD) and is PRIME or NOT PRIME
where N is the integer in question. Do this for every integer.

This is the .dat file
12
61
54
31
12
2
60
26
29
87
29
79
2
14
63
14
53
40
35
20


Explanation / Answer

You'll need to create a bufferedreader that reads the filename stored in args[0] and for each line in the file through an "isPrime(int num)" function, the even/odd bit is simple enough it can be done in the main part of the program. I don't have a development kit on me so I may be off a bit here and there, but here is the basic idea: int num 0 ; BufferedReader br = new BufferedReader(FileReader f = new fileReader(args[0]); while (br.hasNext(){ num = Integer.parseInt(br.readLine()); if (isPrime(num)){ System.out.println("Number is prime"); }else{ System.out.println("Number is not prime"); if ((num%2)==0){ System.out.println("Number is even); } else { System.out.println("Number is odd"); } The IsPrime() part will look like the following: boolean isPrime(int n) { for(int i=2;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote