Java Classic Programming question 50-way 50

Source: Internet
Author: User

There are five students, each student has 3 courses of results, from the keyboard input the above data (including student number, name, three lessons), calculated average results, the original data and calculated average scores are 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 number:");
A[i-1][0] = Ss.nextline ();
System.out.print ("Please enter the" + i + "Student's name:");
A[I-1][1] = Ss.nextline ();
for (int j = 1; j < 4; J + +) {
System.out.print ("Please enter the student's first" + j + "score:");
A[i-1][j + 1] = Ss.nextline ();
}
System.out.println ("\ n");
}
The following calculates the average score
float avg;
int sum;
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 write disk file
String S1;
try {
File F = new file ("E:\\eclipse Workplace\\java Classic Algorithm \\src\\stud.txt");
if (f.exists ()) {
System.out.println ("file exists");
} else {
SYSTEM.OUT.PRINTLN ("File does not exist, creating file");
F.createnewfile ();//does not exist create
}
BufferedWriter output = new BufferedWriter (new FileWriter (f));
for (int i = 0; i < 5; i++) {
for (int j = 0; J < 6; J + +) {
S1 = a[i][j] + "\ r \ n";
Output.write (S1);
}
System.out.println ();
}
Output.close ();
SYSTEM.OUT.PRINTLN ("The data has been written to the e-drive file Stud! ");
} catch (Exception e) {
E.printstacktrace ();
}
}
}

Java Classic Programming question 50-way 50

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.