Java BASIC Programming questions

Source: Internet
Author: User

Package com.test;

Import Java.io.BufferedWriter;
Import Java.io.FileOutputStream;
Import Java.io.FileWriter;
Import Java.io.OutputStream;
Import Java.util.Scanner;

public class Demo {
public static void Main (string[] args) {
/* There are five students, each student has 3 courses of results, from the keyboard input above data (including student number, name, three lessons), calculated
* Average results, the original data and the calculated average score are stored in the disk File "stud". */

Scanner in=new Scanner (system.in);
int n=5;
String [] num=new string[n];//School Number
String [] name=new string[n];//Name
double [[] score=new double[n][3];//Results
Double[]avg=new double[n];//Average Score
for (int i = 0; i < n; i++) {
System.out.println ("Please enter" + (i+1) + "Student Number:");
Num[i]=in.next ();
System.out.println ("Please enter" + (i+1) + "Student's name:");
Name[i]=in.next ();
for (int j = 0; J < 3; J + +) {
System.out.println ("Please enter" + (j+1) + "Gate score");
Score[i][j]=in.nextdouble ();
}
}
for (int i = 0; i < n; i++) {//averaging
for (int j = 0; J < 3; J + +) {
Avg[i] +=score[i][j];
}
AVG[I]=AVG[I]/3;
}
try {
FileWriter fw=new FileWriter ("C:/stud.txt");//write file
BufferedWriter BF =new BufferedWriter (FW);//Buffered stream
for (int i = 0; i < n; i++) {
Bf.write ("Study Number:" +num[i]+ ");//You can write a string of type
Bf.write ("Name:" +name[i]+ "");
Bf.write ("Result: {");
for (int j = 0;j < 3; j + +) {
Bf.write (score[i][j]+ "");
}
Bf.write ("}");
Bf.write ("Average score is" +avg[i]);
Bf.newline ();//Line break
}
Bf.close ();//Release resources
} catch (Exception e) {
E.printstacktrace ();
}


}
}

Java BASIC Programming questions

Related Article

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.