• 问题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);
        }
    }

  • 相关阅读:
    洛谷 AT2000 Leftmost Ball
    洛谷 P1326 足球
    洛谷 P4868 Preprefix sum
    洛谷 P2596 [ZJOI2006]书架
    HDU 3415 Max Sum of Max-K-sub-sequence
    洛谷 P3901 数列找不同
    洛谷 P3609 [USACO17JAN]Hoof, Paper, Scissor蹄子剪刀…
    洛谷 P5749 [IOI2019]排列鞋子
    验证码解决表单重复的原理
    session和浏览器之间的技术内幕
  • 原文地址:https://www.cnblogs.com/vonk/p/3985635.html
Copyright © 2020-2023  润新知