java作业求助!!!!!!!!编一个
import java。io。BufferedReader;
import java。io。InputStreamReader;
import java。io。IOException;
public class Average{
public static void main(String[] args) throws IOException{
while(true){
System。 out。println("please input numbers, put space to split them");
String input = getSNumbers();
int number...全部
import java。io。BufferedReader;
import java。io。InputStreamReader;
import java。io。IOException;
public class Average{
public static void main(String[] args) throws IOException{
while(true){
System。
out。println("please input numbers, put space to split them");
String input = getSNumbers();
int numbers[] = new int[0];
try{
numbers = getNumbers(input);
}catch(NumberFormatException e){
System。
out。println("please input positive numbers");
continue;
}catch(NotPositiveException e){
System。
out。println(e。getMessage());
continue;
}
int total = 0;
for(int i=0; i length; i++){
total += numbers[i];
}
try{
int result = total/numbers。length;
System。
out。println(result);
}catch(ArithmeticException e){
System。out。println("don't input nothing");
}
}
}
public static int[] getNumbers(String numbers){
String []sNumbers = numbers。
split(" ");
if(sNumbers。length==1&&sNumbers[0]。equals("")) return new int[0];
int[] iNumbers = new int[sNumbers。
length];
for(int i=0; i in));
String input = reader。
readLine();
return input;
}
}
class NotPositiveException extends RuntimeException{
public NotPositiveException(String s){
super(s);
}
}。收起