Home  >  Article  >  Java  >  Detailed explanation of an example of Java programming question

Detailed explanation of an example of Java programming question

零下一度
零下一度Original
2017-06-25 13:35:091268browse

There are five students, each student has grades for 3 courses. Enter the above data from the keyboard (including student number, name, grades for the three courses), and calculate the average grade. The original data and the calculated The average score is stored in the disk file "stud".

public class Example50 {
public static void main(String[] args) {
stud();
}

public static void stud() {
Scanner ss = new Scanner(System.in);
String[][] a = new String[5][6];
for (int i = 1; i < 6; i++) {
System.out.print ("Please enter the" + i + "student's student number:");
A [i - 1] [0] = ss.nextline ();
System. out.print("Please enter the name of the " + i + " student: ");
        a[i - 1][1] = ss.nextLine();
            for (int j = 1; j < 4; j++) {
            System.out.print("Please enter the student's " + j + "th grade: "); ss.nextLine();
      }
          System.out.println("\n");
for (int i = 0; i < 5; i++) {
sum = 0;
for (int j = 2; j < 5; j++) {
sum = sum + Integer.parseInt(a[i][j]);
       }
          avg = (float) sum / 3;
                a[i][5] = String.valueOf(avg);
}
// The following disk files
String s1;
Try {
File F = New File ("E: \\ Eclipse Workplace \\ Java classic algorithm \\ src \\ stud.txt.txt ");
if (f.exists()) {
System.out.println("The file does not exist");
if (f.exists());
System.out.println("The file does not exist. Creating file");
                                                                                                                                      . i < 5; i++) {
output.write (s1);
}
System.out.println ();
}
Output.close ();
System.out.println ("The data has been written in E disk file stud! ");
    } catch (Exception e) {
            e.printStackTrace();
                }
                                                               

The above is the detailed content of Detailed explanation of an example of Java programming question. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn