public static void main(String[] args) {
創(chuàng)新互聯(lián)公司致力于互聯(lián)網(wǎng)網(wǎng)站建設(shè)與網(wǎng)站營銷,提供網(wǎng)站設(shè)計、做網(wǎng)站、網(wǎng)站開發(fā)、seo優(yōu)化、網(wǎng)站排名、互聯(lián)網(wǎng)營銷、小程序定制開發(fā)、公眾號商城、等建站開發(fā),創(chuàng)新互聯(lián)公司網(wǎng)站建設(shè)策劃專家,為不同類型的客戶提供良好的互聯(lián)網(wǎng)應(yīng)用定制解決方案,幫助客戶在新的全球化互聯(lián)網(wǎng)環(huán)境中保持優(yōu)勢。
double scores[] = new double[5];
double total = 0;
double avg = 0;
double max = 0;
double min = 0;
int count=0;
String inputStr=null;
System.out.println("請輸入5名學(xué)生的成績:");
Scanner input = new Scanner(System.in);
while(count5){
try{
if(count 5){
System.out.println("請輸入第"+(count+1)+"個分?jǐn)?shù):");
}
inputStr=input.nextLine();
scores[count++]=Double.valueOf(inputStr.trim());
}catch(Exception e){
if(inputStr!=null "exit".equals(inputStr.trim())){
System.out.println("您已成功結(jié)束程序");
System.exit(0);
}
System.out.println("若想結(jié)束請輸入:exit");
System.out.print("您輸入的分?jǐn)?shù)不是數(shù)值類型,");
count--;
}
}
input.close();
Arrays.sort(scores);
min=scores[0];
max=scores[scores.length-1];
for(double score :scores){
total += score;
}
avg=total/scores.length;
System.out.println("總成績是" + total);
System.out.println("最高分是" + max);
System.out.println("最低分是" + min);
System.out.println("平均分是" + avg);
}
//-------------------------------------------------------------------------
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while(true){
Double[] scores = null;
double total = 0;
double avg = 0;
double max = 0;
double min = 0;
int count=1;
ListDouble inputScores=new ArrayListDouble();
String inputStr=null;
System.out.println("請輸入要統(tǒng)計學(xué)生的成績(理論上可以輸入無限個,前提是你有那么大的內(nèi)存):");
while(true){
try{
System.out.println("請輸入第"+count+++"個分?jǐn)?shù),或輸入ok進行計算,離開請輸入exit");
inputStr=input.nextLine();
inputScores.add((double)Double.valueOf(inputStr.trim()));
}catch(Exception e){
if(inputStr!=null "exit".equals(inputStr.trim().toLowerCase())){
System.out.println("您已成功結(jié)束程序");
input.close();
System.exit(0);
}
if(inputStr!=null "ok".equals(inputStr.trim().toLowerCase())){
break;
}
System.out.println("您輸入的分?jǐn)?shù)不是數(shù)值類型,");
System.out.println("若想結(jié)束請輸入exit ,若想計算結(jié)果請輸入ok");
count--;
}
}
if(inputScores.size()==0){
System.out.println("您沒有輸入學(xué)生成績,無數(shù)據(jù)可統(tǒng)計,程序結(jié)束。");
return ;
}
scores=inputScores.toArray(new Double[inputScores.size()]);
Arrays.sort(scores);
min=scores[0];
max=scores[scores.length-1];
for(double score :scores){
total += score;
}
avg=total/scores.length;
System.out.println("總成績是" + total);
System.out.println("最高分是" + max);
System.out.println("最低分是" + min);
System.out.println("平均分是" + avg);
}
}
//
import?java.util.Scanner;
//
public?class?Test2014?{
public?static?void?main(String[]?args)?{
Scanner?sc?=?new?Scanner(System.in);
System.out.println("輸入學(xué)生人數(shù):");
int?n?=?sc.nextInt();
int?sum?=?0;
for(int?i?=?1;i?=?n;++i){
System.out.println("輸入第"+i+"個學(xué)生成績:");
sum?+=?sc.nextInt();
}
System.out.println("總成績是:"+sum+"?"+"平均成績是:"+(double)sum/n);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
System.out.print("請輸入你要計算的科目數(shù):");
int number = scan.nextInt();
float total = 0;
float[] scores = new float[number];
for (int i = 0 ; i number ; i ++) {
System.out.print("請輸入第" + (i + 1) + "門成績:");
float score = scan.nextFloat();
scores[i] = score;
total += score;
}
System.out.println("您的各科成績?nèi)缦拢?);
for (int i = 0 ; i number ; i ++) {
System.out.println((i + 1) + ":" + scores[i]);
}
System.out.println("您的總分為:" + total);
System.out.println("平均分為:" + total/number);
}
import java.util.Scanner;
public class test {
static int s;
public static void main(String[] argv) {
int [] num=new int[20];
Scanner scanner=new Scanner(System.in);
Integer a;
int i;
for(i=1;i=20;i++){
System.out.println("請輸入第"+i+"一個分?jǐn)?shù)(結(jié)束請輸入520嘿嘿):");
a=scanner.nextInt();
num[i-1]=a;
if(a==520){
break;
}
}
for(int m=0;mi-1;m++)
{
s=s+num[m];
}
System.out.println("總共錄入了"+(i-1)+"個分?jǐn)?shù)");
System.out.println("總成績是"+s+"分");
System.out.println("平均分是"+s/(i-1)+"分");
for(Integer m=0;mnum.length-1;m++)
{ if(num[m]0num[m]!=520){
if(num[m]=90)
System.out.println(num[m]+"優(yōu)秀");
else if(num[m]=80)
System.out.println(num[m]+"良好");
else if(num[m]=70)
System.out.println(num[m]+"中等");
else if(num[m]=60)
System.out.println(num[m]+"及格");
else
System.out.println(num[m]+"不及格");
}else break;
}
}
}
我的代碼很簡潔,采納我唄。。。