最后那3个变量就是要统计的
public int addNum() throws IOException{
FileInputStream fin=new FileInputStream("num.data")
DataInputStream din=new DataInputStream(fin)
int i=din.readInt()
i++
FileOutputStream fout=new FileOutputStream("num.data")
DataOutputStream dout=new DataOutputStream(fout)
dout.writeInt(i)
return i
}
num.data里需要先用OutputStream写进去一个0
执行以下代码
public static void main(String args[]) {
FileOutputStream fout
try {
fout = new FileOutputStream("num.data")
DataOutputStream dout=new DataOutputStream(fout)
dout.writeInt(0)
} catch (FileNotFoundException e1) {
e1.printStackTrace()
} catch (IOException e) {
e.printStackTrace()
}
}
import java.util.Scannerpublic class 成绩
{
private static Scanner sc=new Scanner(System.in)
private static int[][] arr=new int[3][2]
private static String[] srr=new String[3]
public static void main(String[] args)
{
System.out.println("\n\t\t\t==========成绩记录==========\n")
init()
}//初始化!
private static void init()
{
for (int i=0i<arr.length i++ )
{
System.out.println("请输入第"+(i+1)+"个学生分数:")
srr[i]="学员"+(char)(65+i)
for (int j=0j<2 j++ )
{
if(j!=1)
System.out.println("语文:")
else
System.out.println("数学:")
arr[i][j]=sc.nextInt()
}
}
for (int i=0i<arr.length i++ )
{
System.out.print(srr[i]+":")
int tem=0
for (int j=0j<arr[i].length j++ )
{
tem+=arr[i][j]
if(j!=1)
System.out.print("\t语文:"+arr[i][j])
else
System.out.print("\t数学:"+arr[i][j])
}
System.out.print("\t该学员总分:"+tem+"\t平均分:"+tem/2+"\n")
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)