[英]Loops and File Statistics Java Program
我写这个程序很困难。 我对JAVA还是很陌生,我有基本的了解。 但是我似乎无法理解它要我做什么。
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();
以下是该程序应从Number.txt中读取的一些行。
87.5517
72.14015
88.24248
60.524
65.38684
94.48039
84.73287
84.74978
73.78996
FileReader
。 为什么要使用PrintWriter
? 一个用于输入(从文件读取),另一个用于输出(写入文件)。 inputFile
的变量。 threeDecimals
对象。 它是DecimalFormat类型。 您可以使用threeDecimals.format(number)
格式化字符串。 通常,所有标准类型中可用的所有方法都在Java SE API文档中 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.