• 问题1-5


    1,生兔子问题(斐波那契数列)

    public class Fibonacci {
    public static void main(String[] args) {
        System.out.println("The rabit of 1th month : 1");
        System.out.println("The rabit of 2th month : 2");
        int f1=1,f2=1,f,m=24;
        for(int i=3;i<=m;i++){
            f=f2;
            f2=f1+f2;
            f1=f;
            System.out.println("The "+i+"th"+" month's rabit is "+f2);
        }
    }
    }

    2,求100至201之间的素数:

    public class primeNum {
        public static void main(String[] args) {
            int count = 0;
            for (int i = 101; i < 200; i += 2) {
                boolean b = false;
                for (int j = 2; j <= Math.sqrt(i); j++) {
                    if (i % j == 0) {
                        b = false;
                        break;
                    } else {
                        b = true;
                    }
                }
                if (b == true) {
                    count++;
                    System.out.println("The prime number is " + i);
                }
            }
            System.out.println("The Number of prime number is " + count);
        }
    }

    3,水仙花数(自恋数):

    public class narcissisticNum {
    public static void main(String[] args) {
        int m,n,l;
        for(int k=101;k<1000;k++){
            m=k/100;
            n=k%100/10;
            l=k%10;
            if((m*m*m+n*n*n+l*l*l)==k){
                System.out.println(k+" is so Narcissitic!!!");
            }
        }
    }
    }

    4,分解质因数:

    import java.util.Scanner;

    public class DecompositionOfTheQualityFactor {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            System.out.println("Please input a int number: ");
            int n = scanner.nextInt();
            int k = 2;
            System.out.print(n + "=");
            while (k <= n) {
                if (k == n) {
                    System.out.print(n);
                    break;
                } else if (n % k == 0) {
                    System.out.print(k + "*");
                    n = n / k;
                } else {
                    k++;
                }

            }
        }
    }

    5,成绩等级判断:

    import java.util.Scanner;

    public class ScoreGrade {
        public static void main(String[] args) {
            int x;
            char grade;
            Scanner scanner = new Scanner(System.in);
            System.out.println("Please input a score:");
            x = scanner.nextInt();
            grade = x >= 90 ? 'A' : x >= 60 ? 'B' : 'C';
            System.out.println("The grade is: " + grade);
        }
    }

  • 相关阅读:
    ORACLE 查看进程数,已执行任务数, 剩余任务数,删除指定任务
    ORACLE 收集统计整个用户数据
    解决Hystrix dashboard Turbine 一直 Loading…… 及其他坑
    利用 Maven 构造 Spring Cloud 微服务架构 模块使用 spring Boot构建
    AES加解密
    JAVA POI XSSFWorkbook导出扩展名为xlsx的Excel,附带weblogic 项目导出Excel文件错误的解决方案
    JAVA 文件的上传下载
    shell启停服务脚本模板
    JAVA 设计模式之 原型模式详解
    JAVA 设计模式之 工厂模式详解
  • 原文地址:https://www.cnblogs.com/vonk/p/3985635.html
Copyright © 2020-2023  润新知