So I have a file with the following values : 3,455;1,67;83,98;0,1;23,178;2.45;3.5;16,88. The code shows the values to the user and it must decide which number is largest and smallest. This is what I've written but I get a different output that what it's supposed to show.
import java.io.File; import java.util.Scanner; import java.io.IOException; public class NumbersNew { public static void main(String[] args) throws IOException { //Create a scanner object which will read the data from the file Scanner sc = new Scanner(new File("/Users/sergeapplemac/Documents/workspace/NumbersNew/src/Numbers2.txt")); sc.useDelimiter("\\s*;\\s*"); while (sc.hasNextLine()) { System.out.println(sc.nextLine()); } //Determine which number was the greatest and which one was the least double largest = Double.MIN_VALUE; double smallest = Double.MAX_VALUE; while(sc.hasNextDouble()) { double val = sc.nextDouble(); if (val < smallest) { smallest = val; } if(val > largest) { largest = val; } System.out.println(largest); System.out.println(smallest); } sc.close(); //Print these numbers System.out.println("The biggest number in the file is: " + largest); System.out.println("The smallest number in the file is: " +smallest); } }
This is the output that I get and I don't understand why:
3,455;1,67;83,98;0,1;23,178;2.45;3.5;16,88
The biggest number in the file is: 4.9E-324
The smallest number in the file is: 1.7976931348623157E308.
Can anyone make a suggestion or point me in the right direction? Thank you!