Java: How to read values from .txt file -
I am writing a program that uses 30 grades from a file and calculates the lowest, highest and average grade I have trouble finding out how to write the loop statement reading each grade and updating the lowest / highest grade and adding that amount before reading the next level.
import java when *. Import java.util. *; Public class midtermast {Public Static Wide Men (string [] AGR) throws IOException {scanner in = new scanner (new flamerdder ("grade.txt")); Int Min = 50; Int highest = 50; Int sum = 0; Int i; For (I = 0, i & lt; 30, i ++) (if (grade; minimum) minimum = grade; if (grade> highest) highest = grade;} double average = sum / 30; System.out.println ("Average score:" + average); System.out.println ("Highest Score is:" + highest); System.out.println ("lowest score is:" + lowest); in Thank you so much: import java.io. *; import java.util. *; Public class midterstest { Public Static Wide Men (string [] AGR) throws IOException {scanner in = new scanner (new flamerdder ("c (I = 0; i & lt; 30; i ++) {int grade = in.nextInt ()); int for minimum = 50; int highest = 50; int sum = 0; int i; ); If (grade & lt; min) minimum = grade; if (grade> highest) highest = grade; yoga + = grade; double = average (sum / 30.0); system.out.println ("average score Is: "+ (int) (average * 100) / 100.0); System.out.println (" highest score: "+ highest); System.out.println (" lowest score is: "+ lowest); in Do something like: (I = 0; I & lt; 30; I ++) {** Float grade = in. Nxtflat (); ** If (grade = Lt; lowest) minimum = grade; And if (grade> gt; highest) highest = grade; Yoga = Grade; }
Do not forget to change every "int" used for "float" for precise.
Comments
Post a Comment