[Program 50]

Source: Internet
Author: User

Question: five students, each having scores for three courses, input the above data from the keyboard (including student ID, name, and score for the three courses) to calculate the average score, store the original data and the calculated average score in the disk file "stud.

Import Java. io. *; import Java. util. *; public class lianxi50 {public static void main (string [] ARGs) {internal Ss = new external (system. in); string [] [] A = new string [5] [6]; for (INT I = 1; I <6; I ++) {system. out. print ("Enter the student ID" + I + "Student:"); A [I-1] [0] = ss. nextline (); system. out. print ("Enter the Student name" + I + ":"); A [I-1] [1] = ss. nextline (); For (Int J = 1; j <4; j ++) {system. out. print ("Enter the student's score" + J + ":"); A [I-1] [J + 1] = Ss. nextline ();} system. out. println ("\ n") ;}// calculate the average 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);} // write the disk file string S1 below; try {file F = new file ("C: \ stud"); If (F. exists () {system. out. println ("file exists");} else {system. out. println ("file does not exist, creating file"); F. createnewfile (); // created if the file does not exist} Bu Fferedwriter 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) ;}} output. close (); system. out. println ("data has been written to the drive C file stud! ");} Catch (exception e) {e. printstacktrace ();}}}

[Program 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.