Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package project5;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.Scanner;
- public class Project5 {
- public static void main(String[] args) throws FileNotFoundException, IOException {
- int[] list = new int[15];
- int[] f = new int[5];
- double target;
- loadGrades(list);
- printGrades(list);
- }
- public static void loadGrades(int list[]){
- Scanner text = null;
- int i = 0;
- try {
- text = new Scanner(new FileReader("proj5Data.txt"));
- } catch (FileNotFoundException ex) {
- System.out.println("Error: File proj5Data.txt not found");
- System.exit(1);
- }
- //reading from the text file to the list[]
- while (text.hasNext()) {
- list[i] = text.nextInt();
- i++;
- }
- text.close();
- }
- public static void printGrades(int list[]) {
- System.out.printf("%3s", list[ 0 ] + " ");
- System.out.printf("%3s", list[ 1 ] + " ");
- System.out.printf("%3s", list[ 2 ] + " ");
- System.out.printf("%3s", list[ 3 ] + " ");
- System.out.printf("%3s", list[ 4 ] + " ");
- System.out.println("");
- System.out.printf("%3s", list[ 5 ] + " ");
- System.out.printf("%3s", list[ 6 ] + " ");
- System.out.printf("%3s", list[ 7 ] + " ");
- System.out.printf("%3s", list[ 8 ] + " ");
- System.out.printf("%3s", list[ 9 ] + " ");
- System.out.println("");
- System.out.printf("%3s", list[ 10 ] + " ");
- System.out.printf("%3s", list[ 11 ] + " ");
- System.out.printf("%3s", list[ 12 ] + " ");
- System.out.printf("%3s", list[ 13 ] + " ");
- System.out.printf("%3s", list[ 14 ] + " ");
- }
- public static int calcMax(int list[]){
- int max = 0;
- for(int n:list){
- if(max < n){
- max = n;
- } else if(n > max){
- max = n;
- }
- System.out.println("The maximum grade is" + max);
- }
- return max;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement