Java菜鸟入坑-循环练习题

 

public class try8_2 {
public static void main(String[] args) {
    //假设某员工的年薪是3w,年增长率是6%,求10年后的年薪和未来10年内的总收入
double x=30000;
double sum=0;
for(int i=1;i<11;i++) {
    x*=1.06;
    sum+=x;
}
System.out.println(x);
System.out.println(sum);

   //猴子偷桃  第一天吃一半+1个,第二天吃剩下的一半+1个,以后都吃剩下的一半+1个 到第10天只剩一个了 问第一天摘了多少桃子
   int y=1;
  for(int i=9;i>0;i--) {
     y= (y+1)*2;
  }
System.out.println(y);
 //判断是否是闰年
 //闰年:1.能被400整除 2.能被4整除但不能被100整除
 int year=(int)(Math.random()*3000+1);//随机一个1-3000内的整数
 if(year%400==0 || ((year%4==0)&&(year%100!=0))) {
     System.out.print(year+"是闰年");
 }
 else
     System.out.println(year+"不是闰年");
 //给定3个整数(1-20) 把三个整数由小到大输出
 int o=(int)(Math.random()*20+1);
 int p=(int)(Math.random()*20+1);
 int q=(int)(Math.random()*20+1);
 System.out.println(o+" "+p+" "+q);
 int temp;
 if(o>p) {
     temp=o;
     o=p;
     p=temp;
 }
 if(o>q) {
     temp=o;
     o=q;
     q=temp;
 }
 if(p>q) {
     temp=q;
     q=p;
     p=temp;
 }
     System.out.println(o+" "+p+" "+q);
    //有一个不多于3位的整数 求它是几位数 分别打印出数字
    //0-999
     int h=(int)(Math.random()*999);
     //System.out.println(h);
     if(h>0&&h<10) {
         System.out.println(h+"是一位数");
     }
     if(h>9&&h<100) {
         System.out.println(h+"是二位数");
     }
     if(h>99&&h<1000) {
         System.out.println(h+"是三位数");
     }
     System.out.println("逆向输出为:");
     while(h%10!=0) {
         System.out.println(h%10);
         h=h/10;
     }
     //输出0-9 但不包括5
     for(int j=0;j<10;j++) {
         if(j==5) {
             continue;
         }
         System.out.print(j+"\t");
     }
     //找出大于200最小的质数
     for(int r=200;;r++) {
         boolean a=true;
     for(int u=2;u<r;u++) {
         if(r%u==0) {
             a=false;
             break;
         }
    
     }
     if(a) {
         System.out.println("\n"+r);
         break;
     }
     }
     
}
}
运行结果:

53725.43089628564
419149.27916771255
1534
966不是闰年
15 7 1
1 7 15
623是三位数
逆向输出为:
3
2
6
0    1    2    3    4    6    7    8    9    
211

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值