要的是JAVA的程序,不要嘴说的语言!

来源:百度知道 编辑:UC知道 时间:2024/06/21 03:45:11
用户输入10个成绩,将成绩存入数组中。
编写方法:给数组赋值,返回总分,返回平均分,排序,显示
要用到方法调用
----------------------------------------
刚学1星期 帮帮忙。不要写些 很菜很垃圾之类的话。每个人都有第一步
注意::::“方法调用“

//请在命令行下运行本程序:
//自己不会笨到这地步吧,方法调用自己去改一下就行了,要不回家种地去得了,还学什么JAVA
public class T3 {
public static void main(String[] args) throws Exception{
int len = 10;//要求输入的成绩个数
int count = 0;//计数器
int read = 0;//读取的字节长度
float[] results = new float[len];//保存成绩的数组
byte[] buff = new byte[1024];
//成绩录入,使用System.in对象录入.
while(count<len){
System.out.println("请输入第"+(count+1)+"位学生的成绩:");
read=System.in.read(buff);
try{
results[count]=Float.parseFloat(new String(buff,0,read));
++count;
}catch(Exception e){System.out.println("输入无效!");}
}
//求总成绩:
float total = 0;
for(int i=0; i<len; i++){
total+=results[i];
}

float avg=total/len;//求得的平均分

//排序(升序)
for(int i=0; i<len-1; i++){
if(results[i]>results[i+1]){
results[i]+=results[i+1];
results[i+1]=results[i]-results[i+1];
results[i]=results[i]