【发布时间】:2013-03-03 15:20:19
【问题描述】:
我正在学习 Java,但对这一挑战感到困惑。我搜索了我的书和此处的有用链接,但没有找到与我正在做的事情有关的任何内容。
挑战是在记事本文件中创建一个数字列表。 java程序必须导入数字,比较每个数字,然后打印出列表中哪个数字具有最低值。
在此处输入代码
这是我的代码
import java.io.*;
import java.util.Scanner;
/**
Aaron Moores
March 2, 2013
Input: Numbers file
Output: Highest number, lowest number
*/
public class LargenSmall
{
public static void main(String[] args) throws IOException
{
String filename; //Numbers file
double lowest;
//Open the file
File file = new File("Number.txt");
Scanner inputFile = new Scanner(file);
lowest = 0.0;
//Read all the values in Numbers file and find the lowest value
while (inputFile.hasNext())
{
//Read a number in the file
double number = inputFile.nextDouble();
lowest = < number;
}
//Close file
inputFile.close();
//Print out lowest value in the list
System.out.println("The lowest number in your file called, " +
"Numbers.txt is " +lowest);
}
}
我的问题是弄清楚如何格式化比较每个值以存储最小值的代码行。如果我将 (lowest = minimum
请帮帮我。 谢谢
【问题讨论】: