0
点赞
收藏
分享

微信扫一扫

Day 31

船长_Kevin 2022-02-26 阅读 49

java复习与整理195

  1. package demo02;
    
    public class Application {
        public static void main(String[] args) {
            /*  需求:世界最高峰珠穆朗玛峰为8848.43m = 8848430mm ,一张纸的厚度为0.1毫米,若纸无限大,
            则需要对折多少次能到达珠穆朗玛峰的高度?
             */
            Test s1 = new Test();
            s1.high();
        }
    }
    --------------------------------------------
    package demo02;
    
    public class Test {
        public void high(){
            int H = 88484300;   // 便于好算,扩大10倍
            int i = 1;
            int n = 0;
            while ( i < H){
                i = i*2;
                n++;
            }
            System.out.println("需要对折"+n+"次");
    
        }
    }
    ==========================================
    需要对折27Process finished with exit code 0
    
  2. package demo01;
    
    public class Application {
        //   遍历100到999的水仙花数
        public static void main(String[] args) {
            Test n1 = new Test();
            n1.calculate();
        }
    }
    --------------------------------------
    package demo01;
    
    public class Test {
        public void  calculate(){
            int n = 0;
            int m =0;
            for (int i = 152; i < 999 ; i++) {
                int a = i/100;     //  百位上的数字
                int b = i/10%10;   //  十位上的数字
                int c = i%10;      //  各位上的数字
                if ( i == a*a*a + b*b*b + c*c*c ){
                    n = i;
                    m++;
                    System.out.print(n+" ");
                }
    
            }
            System.out.println();
            System.out.println("水仙花数的个数为:"+m);
        }
    }
    =====================================
    水仙花数的个数为:4
    
    Process finished with exit code 0
    
举报

相关推荐

day31_JDBC

day31_CSS

day31—编程题

嵌入式学习 Day 31

Day31 贪心算法

蓝桥杯31日冲刺 Day 3

面试经典150题——Day31

0 条评论