11.10 面向对象程序设计实验报告java

1.实验2 循环结构 、选择结构
题目:

  1. 输出1-100的所有偶数之和。
  2. 编程实现求三个数中的最大值。
  3. 编写程序,将百分制成绩转换为四级分制成绩。如果成绩的取值范围是[0,60),则打印输出“不及格”;如果取值范围是[60,75),则打印输出“及格”;如果取值范围是[75,90),则打印输出“良好”;如果取值范围是[90,100],则打印输出“优秀”。其他的取值范围均打印“该成绩不合法”。
  4. 编程求(结果是:0.688)
  5. 利用公式求π的近似值,直到最后一项的绝对值小于10-6为止。

四、程序源代码(核心)与实验结果

第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);   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

干饭人小周26

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值