肖申克的救赎主题思想:关于JAVA的题目,小弟请各位高手指导下

来源:百度文库 编辑:高校问答 时间:2024/04/29 03:41:48
1.编写一个程序
在标准输入和输出窗口中提示输入两个整数,然后接收这两个整数,并输出它们的和.下面是运行过程的示例:
Please input an integer :45
Please input the second integer :23
Result :45+23=68
上面一二行的45和23是用键盘输入的,其余字符是程序输出的
2. 编写一个程序:
要求输入五个学生的成绩(从0到100的整数),并将这五个整数保存到文件"data.exe"中.然后再编写一个程序:从文件"data.exe"中读取这五个学生的成绩,并计算他们的平均数,然后按从小到大的顺序输出这五个学生的成绩.
最后,谢谢每个高手的帮助!

import java.io.*;

public class demo04
{
public static void main(String[] args){
DataInputStream in = new DataInputStream(new BufferedInputStream(System.in));
String s;
String a,b;
String s1="Please input integer ";
int i=0;
a="0";
b="0";
System.out.print(s1+" 请输入第一个数:");
try {
while((s = in.readLine()).length() != 0)
{
i=i+1;
if(i==1) { a=s;System.out.print(s1+"请输入第二个数");}
if(i==2) { b=s;break;}
}
int c=Integer.parseInt(a)+Integer.parseInt(b);
System.out.print("计算结果:"+String.valueOf(c));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

看不懂呀!!