Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: My code doesn't show the right output

  1. #1
    Junior Member
    Join Date
    May 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default My code doesn't show the right output

    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!

  2. #2
    Junior Member
    Join Date
    May 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My code doesn't show the right output

    I did some changes in the code and now it works.

Similar Threads

  1. How to show the output image (using java) as resultant image in webpage
    By Mumpy Zinu in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: February 24th, 2014, 08:00 AM
  2. Replies: 1
    Last Post: September 27th, 2013, 04:51 AM
  3. Forum section to show the code?
    By beer-in-box in forum Totally Off Topic
    Replies: 2
    Last Post: March 8th, 2013, 08:36 AM
  4. please show me how to expand my code
    By me. in forum Java Theory & Questions
    Replies: 4
    Last Post: October 31st, 2012, 03:17 PM
  5. Show output on jTextArea
    By HugoMonteiro in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 18th, 2012, 07:35 PM