辛苦大家帮我写一个学生管理程序,是这样的: 有成绩 98、79、 67、 90、 88、 64、 53、 97 不要求有图形界面,在Editplus里面能运行就可以,当我输入1时 显示平均成绩 当输入2时显示总和。多谢!
解决方案 »
- 急!各位帮帮忙 有道字符串的题实在不会啊
- java 如何从MID格式的音频文件中提取音符?
- 如何用NETBEANS编写一个打开图片的小程序~~
- 连接sql server2000 我该用哪个补丁?
- 请教怎么在java中做成像csdn左边的导航栏呢?
- Checkbox组.getSelectedCheckbox().getName()
- 用loadrunner测纯java程序
- 请问:运行rmi的server端时,为何总是报ClassNotFoundException?
- 求救,应该是encoder的问题,散分!
- 如何做一个类似MyEclipse能自动提示的东西
- 对象数组的强型转换问题
- java有没有必要被编译成exe文件
大哥,不会吧,这样的问题也要求人
import java.io.*;
class NotValidNumException extends Exception{
}
public class Score{
public static int getChoose()
throws IoException,NumberNotFormatException,NotValidNumException{
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
int i = 0;
i = Integer.parseInt(br.readLine());
if(i != 1 || i != 2){
throw new NotValidNumException();
}
return i;
}
public static int getArraySum(int[] num){
int sum = 0;
for(int i = 0 ; i < num.length ; i++ ){
sum += num[i];
}
return sum;
}
public static int getArrayAvg(int[] num){
int sum = Score.getArraySum(num);
int avg = sum/num.length;
return avg;
}
public static void main(String[] args){
int[] num = {98,79,67,90,88,64,53,97};
boolean flag = true;
Integer choose = null;
while(flag){
System.out.println("please input your choose:");
try{
choose = Score.getChoose();
}catch(NumberNotFormatException e){
System.out.println("the inputed number is error!please input again!");
continue;
}catch(NotValidNumException ee){
System.out.println("the inputed number is invalid number!"
+ "please input again!");
continue;
}catch(IOException eee){
System.out.println(eee.getMessage());
continue;
}
flag = false;
}
if(choose == 1){
System.out.println("These number's Avg : " + getArrayAvg);
}
if(choose == 2){
System.out.println("These number's Sum : " + getArraySum);
}
}
}
System.out.println("These number's Avg : " + getArrayAvg);
}
if(choose == 2){
System.out.println("These number's Sum : " + getArraySum);
}
红色部分编绎能过么???
public static float getAverage(float[] temp) {
float tempV = 0;
int m = 0;
for (int i = 0; i < temp.length; i++) {
tempV += temp[i];
m++;
} return tempV / m;
} public static float getSum(float[] temp) {
float tempV = 0;
for (int i = 0; i < temp.length; i++) {
tempV += temp[i];
}
return tempV;
} public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
float[] temp = { 89, 97, 23, 47, 86, 80, 32, 128 };
while(true){
System.out.println("start");
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(input);
char tempCharater = (char) br.read();
System.out.println(tempCharater);
if (tempCharater == '1') {
System.out.println("成绩的平均数:");
System.out.println(getAverage(temp));
} else if (tempCharater == '2') {
System.out.println("成绩的总和:");
System.out.println(getSum(temp));
} else
System.out.println("没有任何操作");
}
}
直接用EXCEL算了.