Reputation: 57
I am have a difficult time writing this program. I am very new to JAVA and I have the basic understanding. But I can't seem to understand what it is asking me to do.
import java.text.DecimalFormat;
import java.util.Scanner;
import java.io.*;
public class StatsDemo
{
public static void main(String [] args) throws IOException
{
double sum = 0;
int count = 0;
double mean = 0;
double stdDev = 0;
String line;
double difference; //difference between the value and the mean
DecimalFormat threeDecimals = new DecimalFormat("0.000");
Scanner keyboard = new Scanner (System.in);
String filename;
System.out.println("This program calculates statistics"
+ "on a file containing a series of numbers");
System.out.print("Enter the file name: ");
filename = keyboard.nextLine();
Here are some of the lines from Number.txt that this program is supposed to be reading from.
87.5517
72.14015
88.24248
60.524
65.38684
94.48039
84.73287
84.74978
73.78996
Upvotes: 0
Views: 972
Reputation: 34618
FileReader
in the comments. Why do you use a PrintWriter
? One is for input (reading from a file), the other is for output (writing to a file). inputFile
there.threeDecimals
object you were supplied with. It is of type DecimalFormat. You format the string by using threeDecimals.format(number)
.In general, all of the methods available in all of the standard types are in the Java SE API Documentation.
Upvotes: 1