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: reading floats from file and output minimum and maximum temperatures

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default reading floats from file and output minimum and maximum temperatures

    Hi guys,
    I'm new to this forum and I'm excited to learn more about java with your help
    I'm learning how to read numbers from file.
    in this coding, I want to read floats from file and calculate minimum and maximum temperatures from it and get a output like this :
    -10 ≤ temp < 0
    0 ≤ temp < 10
    10 ≤ temp < 20
    20 ≤ temp < 30
    30 ≤ temp < 40

    here are my coding:

    import java.util.*;
    import java.io.*;
     
    public class max {
     
        public static void main(String[] args) {
            if (0 < args.length) {
         File test = new File(args[0]);
     
    Scanner t = new Scanner( new FileInputStream(test));
    while(t.hasNextFloat()){
           float x = t.nextFloat();
           System.out.println(x);
    }
        }

    and here an example of my file:
    12.8701128	-19.08983034
    37.95429681	51.67538099
    14.815839	8.192769202
    -16.12037567	58.16092338
    43.11540189	-3.681658176
    59.099608	9.176666748
    21.34655982	9.509843699
    2.620998417	56.92736179
    -11.9657946	66.29716149
    5.732177907	-14.88076519
    -11.43389073	55.27621116
    49.09869394	45.01297259

    any idea how can I separate minimum and maximum of each raw and print it like above?
    thank you


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: reading floats from file and output minimum and maximum temperatures

    First step, what do you think you will need? Think about how you would work out the min and max values using pen and paper and I read out numbers one at a time.
    Improving the world one idiot at a time!

Similar Threads

  1. Reading in floats into JPanel?
    By syregnar86 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 31st, 2013, 11:23 AM
  2. Reading text file and counting the number of words, integers, and floats.
    By Jsmooth in forum File I/O & Other I/O Streams
    Replies: 11
    Last Post: April 12th, 2012, 06:39 PM
  3. Reading file of floats into array list and sorting into subsets
    By Skave in forum Collections and Generics
    Replies: 2
    Last Post: November 9th, 2011, 07:03 PM
  4. Reading ant output when exec the command
    By cipm66 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: October 23rd, 2010, 01:48 PM
  5. Java program to find the minimum and maximum values of input data
    By awake77 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 20th, 2008, 05:12 PM