Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7187673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:53:59+00:00 2026-05-28T18:53:59+00:00

I am reading Earth quake Stats from a file and I need to be

  • 0

I am reading Earth quake Stats from a file and I need to be able to determine the Min and max values of the Magnitudes. there are about 831 magnitudes. I tried to create a local double max = Double.MAX_VALUE; double min = Double.MIN_VALUE; variables and compare those to the double magnitude values I am pulling from the file, but when I return the value, it just gives me the lowest and highest values for any double value. Here is my code so far.

Data from file example:

1.6,"Southern California","Wednesday, January 18, 2012 19:19:12 UTC"
1.8,"Southern California","Wednesday, January 18, 2012 19:03:00 UTC"
1.8,"Southern California","Wednesday, January 18, 2012 18:46:53 UTC"
4.7,"Bonin Islands, Japan region","Wednesday, January 18, 2012 18:20:40 UTC"
1.6,"Southern California","Wednesday, January 18, 2012 17:58:07 UTC"
1.0,"Northern California","Wednesday, January 18, 2012 17:48:03 UTC"
5.2,"Santa Cruz Islands","Wednesday, January 18, 2012 17:26:02 UTC"
import java.util.*;
import java.io.*;

public class QuakeStates2 
{       

    public static void main(String[] args) throws IOException
        {       
            double count = 0.0;
            double mag = 0.0;
            double total = 0.0;
            double average = 0.0;
            double max = Double.MAX_VALUE;
            double min = Double.MIN_VALUE;
            String area = null;
            String date = null;


            Scanner keyboard = new Scanner(System.in); //Setup the Keyboard scanner
            System.out.print("Enter the filename: "); // User input for the filename

            String filename = keyboard.nextLine();  //Scanner stores the file name as a String Value

            File file = new File(filename);         //File turns the Scanner input into a file
            Scanner inputFile = new Scanner(file);  //inputFile holds the file info and Reads up to the comma

            while (inputFile.hasNextLine()) 
            {
                String line = inputFile.nextLine();
                count++;
                StringTokenizer str = new StringTokenizer(line);

                if (str.hasMoreTokens())
                    {
                    mag = Double.parseDouble(str.nextToken(",")); 
                    area = str.nextToken();
                    date = str.nextToken("\\w");
                    //System.out.println(mag);
                    //System.out.println(area);
                    //System.out.println(date);
                    }
                if ( mag > max)
                {
                    max = mag;
                }

                if ( mag < min)
                {
                    min = mag;
                }
                total = mag+total;
                average = total/count;

            }

            inputFile.close();

            System.out.println("# of Lines in the file: " + count);
            System.out.println("Sum of Magnitudes: " + total);
            System.out.println("Average Magnitude: " + average);
            System.out.println("Max Magnitude: " + max);
            System.out.println("Min Magnitude: " + min);


        }

    }

Results:

Enter the filename: C:\Users\Owner\Desktop\workspace\QuakeStatistics\quakes1.2012.txt
# of Lines in the file: 821.0
Sum of Magnitudes: 1747.0000000000007
Average Magnitude: 2.127892813641901
Max Magnitude: 1.7976931348623157E308
Min Magnitude: 4.9E-324
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:54:00+00:00Added an answer on May 28, 2026 at 6:54 pm

    Change

    double max = Double.MAX_VALUE;
    double min = Double.MIN_VALUE;
    

    to

    double max = Double.MIN_VALUE;
    double min = Double.MAX_VALUE;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading XML from a file into a variable can be done like this: [xml]$x
Reading the docs, I'd expect $(#wrap2).remove(.error) to remove all .error elements from #wrap2 .
Reading manual about Sling http://sling.apache.org/site/46-line-blog.html added folder blog and blog.html to destination: \launchpad\content\src\main\resources\content\ but
Reading the MCIMX50 Application Processor Reference Manuals on page 1368 (Section 33.3) there is
Reading the Scala by Example book and there is this example when Martin explains
Reading through this excellent article about safe construction techniques by Brain Goetz, I got
Reading about the Dispose pattern , I see the documentation repeatedly refer to cleaning
Reading some questions here on SO about conversion operators and constructors got me thinking
My WPF application is reading a text file and populating a listbox. Whenever I
Reading code from other posts, I'm seeing something like this. struct Foo { Foo()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.