Note that there are some explanatory texts on larger screens.

plurals
  1. POcomparing numbers in list from an input file
    primarykey
    data
    text
    <p>I'm in intro to java and am stumped on this one challenge. I have searched my book and the helpful links on here but haven't found anything that pertains to what I'm doing.</p> <p>The challenge is to create a list of numbers in a notepad file. The java program has to import the numbers, compare each number together, then print out what number in the list has the lowest value.</p> <p>enter code here</p> <p>here is my code</p> <pre><code>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 = &lt; 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); } } </code></pre> <p>My problem is figuring out how to format the code line that compares each value to store the lowest value. If I change (lowest = lowest &lt; number) to (lowest = lowest + number) and add an accumulator the program will add all the values in my file and display them, so I know the import part of the program works. I'm just unclear on how to formulate a compare statement to have it display the lowest value.</p> <p>please help I am stumped. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload