Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do i input a file and write code to find the highest number in the list
    text
    copied!<p>I am new to java and thanks to this site figured out how get the lowest value from the list but I am still struggling with how to get the same code to work for the highest value. I've been working on it for the past 2 hours. Again any help is appreciated</p> <pre><code>import java.io.File; import java.io.IOException; import java.util.Scanner; public class LargenSmall { public static void main(String[] args) throws IOException { String filename; //Numbers file double lowest = Double.POSITIVE_INFINITY;//lowest number in list double highest; //highest number in list //Open the file File file = new File("Numbers.txt"); Scanner inputFile = new Scanner(file); //Set lowest to zero //Read all the values in Numbers file and find the lowest value while (inputFile.hasNext()) { //Read the numbers in the file and compare each value to find lowest value double number = inputFile.nextDouble(); if (number &lt; lowest) lowest = number; } //Set highest to zero highest = 0.0; //Read all the values in Numbers file and find the highest value while (inputFile.hasNext()) { //Read the numbers in the file and compare each value to find highest value double number = inputFile.nextDouble(); if (number &gt; highest) highest = number; } //Close file inputFile.close(); //Print out the lowest value in the list System.out.println("The lowest number in your file called, " + "Numbers.txt is " + lowest + "."); //Print out the highest value in the list System.out.println("The highest value in the list is " + highest); } } </code></pre> <p>I have tried a few variations and highest value keeps coming back as 0.0</p>
 

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