The file input.txt contains all of the winning number combinations from the Miss
ID: 3549382 • Letter: T
Question
The file input.txt contains all of the winning number combinations from the Missouri Lottery since it took its current form on January 3, 1998. The data is in a file called "input.txt" All of the data in the file is integer. You should read the file as integers and do calculations in integers as much as possible. You are to read the data in the file and then print out the following information:
Use the format shown below. Use the System.out.printf() command for the printing:
There were 9888 numbers read.
The number 7 was read 225 times (2.275%)
The number 13 was read 232 times (2.330%)
You should print your report from a method with a declaration similar to the following:
public static void printReport(int total, int sevens, int thirteens)
Explanation / Answer
please rate - thanks
any questions, or changes needed ask
sample run, and input file
import java.util.*;
import java.io.*;
public class FileIn
{public static void main(String[] args)throws FileNotFoundException
{Scanner input=new Scanner(new File("input.txt"));
int seven=0,thirteen=0,total=0,in;
while(input.hasNextInt())
{in=input.nextInt();
if(in==7)
seven++;
else if(in==13)
thirteen++;
total++;
}
printReport(total,seven,thirteen);
}
public static void printReport(int total, int sevens, int thirteens)
{System.out.printf("There were %d numbers read ",total);
System.out.printf("The number 7 was read %d times (%.3f%%) ",sevens,sevens/(double)total*100.);
System.out.printf("The number 13 was read %d times (%.3f%%) ",thirteens,thirteens/(double)total*100.);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.