11.10 オブジェクト指向プログラミング実験報告 java

1. 実験 2 サイクル構造、選択構造
トピック:

  1. 1 から 100 までのすべての偶数の合計を出力します。
  2. 最大 3 つの数を見つけるプログラム。
  3. パーセンタイルの成績を 4 段階の成績に変換するプログラムを作成します。グレードの値の範囲が [0,60) の場合は「不合格」を出力し、値の範囲が [60,75) の場合は「合格」を出力し、値の範囲が [75,90) の場合は「合格」を出力します。値の範囲が [90,100] の場合、印刷結果は「優良」です。その他の値の範囲については、「結果は無効です」が出力されます。
  4. プログラムでシーク (結果: 0.688)
  5. 式を使用して、最後の項の絶対値が 10-6 未満になるまで、π の近似値を求めます。

4. プログラムのソースコード(コア)と実験結果

質問1:

 int i=0;int sum=0
while (i<100){
    i++;
    if(i%2==1)
        continue;sum=sum+i;
}System.out.print(sum); 

質問2:

int []a=new  int [3];
Scanner sc=new Scanner(System.in);
for(int i=0;i<3;i++){
    System.out.print("请输入第"+(i+1)+"个数:");
    a[i]=sc.nextInt();
}
if (a[0]>=a[1] && a[0]>=a[2]){
    System.out.print(a[0]);
}
else if(a[1]>=a[2]){
    System.out.print(a[1]);
}
else{
    System.out.print(a[2]);
}  

質問 3:

Scanner sc=new Scanner(System.in);
System.out.print("请输入成绩:");
float cj=sc.nextFloat();
if(cj>=0 && cj<60){
    System.out.print("不及格");
}
else if (cj>=60 && cj<75){
    System.out.print("及格");
}
else if (cj>=75 && cj<90){
    System.out.print("良好");
}
else if (cj>=90 && cj<=100){
    System.out.print("优秀");
}
else{
    System.out.print("该成绩不合法");
}    

質問 4:

double sum=0;
double a=0;
for (int i=1;i<=100;i++){
    a=Math.pow(-1,i+1);
    sum=sum+(a*(1.0/i));
}
System.out.print(String.format("%.3f",sum));  

質問 5:

double sum=0;
int i=1,f=-1;
while (1.0/i>=Math.pow(10,-6)){
    f=-f;
    sum=sum+f*(1.0/i);
    i=i+2;
}
System.out.print(4*sum);   

おすすめ

転載: blog.csdn.net/zlc2351951436/article/details/103003773