package cn.com.day02;
import java.util.Scanner;
import javax.print.attribute.standard.MediaSize.JIS;
public class JiSuanQi {
/*
* public double sum(double a,double b,double c){ double s=0; s=a+b+c;
* return s; } public double pjz(double a,double b,double c){ double s=0;
* s=(a+b+c); s=s/3; return s; }
*/
/*
* int m; System.out.println("请输入你要进行计算的科目的数目"); Scanner sn=new
* Scanner(System.in); m=sn.nextInt();
* System.out.println("请输入你要计算的成绩,将会进行总分计算......"); float [] sz=new float
* [m]; for(int f=0;f<m;f++){ Scanner sc=new Scanner(System.in);
* sz[f]=sc.nextFloat(); } float sum=0; for(int f1=0;f1<m;f1++){
* sum=sum+sz[f1]; } System.out.println(sum);
*
* JiSuanQi js=new JiSuanQi(); float su=(float) js.sum(a,b,c);
* System.out.println(su);
*/
/*
* int m1; System.out.println("请输入你要进行计算的科目的数目"); Scanner sn1=new
* Scanner(System.in); m=sn1.nextInt();
* System.out.println("请输入你要计算的成绩,将会进行总分计算......"); float [] sz1=new float
* [m]; for(int f=0;f<m;f++){ Scanner sc=new Scanner(System.in);
* sz1[f]=sc.nextFloat(); } float sum1=0; for(int f1=0;f1<m;f1++){
* sum1=sum1+sz1[f1]; } System.out.println(sum1/m);
*/
/*
* System.out.println("请输入你的三门科目的成绩,以下会进行平均数计算......"); Scanner s=new
* Scanner(System.in); float a1 = s.nextFloat(); float b1 = s.nextFloat();
* float c1= s.nextFloat(); JiSuanQi js1=new JiSuanQi();
* System.out.println("平均数:"+js1.pjz(a1, b1, c1));
*/
public double sum() {
int m;
System.out.println("请输入你要进行计算的科目的数目");
Scanner sn = new Scanner(System.in);
m = sn.nextInt();
System.out.println("请输入你要计算的成绩,将会进行总分计算......");
float[] sz = new float[m];
for (int f = 0; f < m; f++) {
Scanner sc = new Scanner(System.in);
sz[f] = sc.nextFloat();
}
float sum = 0;
for (int f1 = 0; f1 < m; f1++) {
sum = sum + sz[f1];
}
System.out.println(sum);
return sum;
}
public double avg() {
int m1;
System.out.println("请输入你要进行计算的科目的数目");
Scanner sn1 = new Scanner(System.in);
m1 = sn1.nextInt();
System.out.println("请输入你要计算的成绩,将会进行平均值计算......");
float[] sz1 = new float[m1];
for (int f = 0; f < m1; f++) {
Scanner sc = new Scanner(System.in);
sz1[f] = sc.nextFloat();
}
float sum1 = 0;
for (int f1 = 0; f1 < m1; f1++) {
sum1 = sum1 + sz1[f1];
}
System.out.println(sum1 / m1);
return sum1 / m1;
}
public static void main(String[] args) {
for (int g = 0; g < 9; g++) {
int j = 0;
System.out.println("请输入指定的数字:0--代表求和,1--代表求平均值");
Scanner ss = new Scanner(System.in);
j = ss.nextInt();
if (j == 1 || j == 0) {
switch (j) {
case 0:
JiSuanQi jj = new JiSuanQi();
jj.sum();
break;
case 1:
JiSuanQi js = new JiSuanQi();
js.avg();
break;
default:
System.out.println("此程序只适用于计算求和与求平均值!!!!");
break;
}
} else {
System.out.println("请规范输入---0或1");
continue;
}
}
}
}
java实现简单的计算器功能
最新推荐文章于 2024-07-14 19:36:05 发布