string - How to Determine the Max and Min Values Read in From a Text File in Java -


I am doing homework for a classroom, and I'm looking for some helpful hints, not a complete solution. Actually, I want to write a Java program that reads in a text file and lists the information line by line, lists the row number, and finally, prints the maximum and minimum value and the years related to each . The text file contains year and temperature for that year. So, it lists something like "1900 50.9" I'm not meant to use an array or scanner, it's part of the assignment. I have been successful in successfully achieving the line-line related to the line with program and line counting to print each year. I was told, and used the loop at that time. Now, my only issue is accessing the text file in such a way that I can differentiate all the temperatures in any way, which is the maximum and which is the minimum, and in which year every one has come. I have not asked for help because I wanted to be able to understand it on my own but due to late penalties, the assignment is no longer worth any credit. Any help really will be appreciated, because I still want to solve it. Thank you.

This is what I have.

  Public Class Men {/ ** * Param Command Line Arguments * / Public Static Zero Main (string [] args throws exceptions (file temps = new file ("temps.txt" ); // temps.txt file creates paths for fileReader textReader = new FileReader (temps); // temps.txt file input from input in file reader BufferedReader kb = new BufferedReader (textReader); // file reader string from templatelist Use buffer reader to keep temps.txt file information; // string variable named tempList int lineCount = 0; // Create an integer variable called ain; name the string string sep = ": temp"; // strip variables that SEP (small for separation) and set it equal to literal string ":" string space = ""; // string variable Name and set it to be a real space between the text System.out.println ("The information provided by the following file input."); While ((tempList = kb.readLine ()) = Null { // While loop stating that until the text file is in Not just the value of reading (not zero), Systemkoutkprintln ( "Line" Lainkount + ++ + "old" + TempListkreplace (space, Sipi)); // print the line number (line count ++), ":" between the "year" and the number (tempList.replace (space, sep)}} from the temps.txt file "  

}

The output is as follows:

  Line 0: Year 1900: Temporary 50.9 Line 1: Year 1901: Temporary 49 Line 2: Year 1902: Temporary 49.7 Line 3: Year 1903: Temporary 49.5 Line 4: Year 1904: Temporary 47.1 Line 5: Year 1905: Temporary 49.1   

etc. All the way ... Line 99: Year 1999: Temporary 52.7 Successful (Total Time: 0 seconds)

Here's a way to do this:

  string tempList; // tempList called called string variable int lineCount = 0; // named integer variable name line count string sep = ":" "temporary"; // create sep called strip variables (small separation) and it literally Set string equal to ":" string space = ""; // string variable is named and set it equal to actual space between text string maxValueYear = ""; String minValueYear = ""; Double max value = 0; Double minvalue = double.mx_avn; System.out.println ("The information given by file input is below."); While ((tempList = kb.readLine ())! = Null) {// while loop stating that unless the value of reading now text file also (not zero), the string year = tempList.substring (0, TempList.indexOf (space)); Double temp = double.valof (tempList.substring (tempList.indexOf (space), tempList.length ())); If (floating & gt; maximum value) {maxValue = temp; MaxValueYear = year; } If (temp & lt; minValue) {minValue = temp; MinValueYear = Year; } System.out.println ("Line" + LineCount ++ + ": Year" + tempList.replace (location, sep)); // line number (Lainkount ++) print that, "among information temps.txt file" and numbers between years (tempList.replace (space, sep)} System.out.println ( "Minimum temp year + + Mintval + "and" + Mintvalu "); System.out.println (" max temp old "+ maximum value + in" and "+ maximum value");   < / Div> 

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -