zoukankan      html  css  js  c++  java
  • 11~15

    11,含不同数字的三位数:

    public class ThridNum {
        public static void main(String[] args) {
            int count = 0;
            for (int x = 1; x < 5; x++) {
                for (int y = 1; y < 5; y++) {
                    for (int z = 1; z < 5; z++) {
                        if (x != y && y != z && x != z) {
                            count++;
                            System.out.println(x * 100 + y * 10 + z);
                        }
                    }
                }
            }
            System.out.println("All have " + count + " thrrir numbers.");
        }
    }

    12,求奖金数:

    import java.util.Scanner;

    public class Bonus {
        public static void main(String[] args) {
            System.out.println("Please input the gain this year: ");
            Scanner scanner = new Scanner(System.in);
            int Gain = scanner.nextInt();
            int Bonus;
            if (Gain <= 100000) {
                Bonus=(int) (Gain * 0.1);
                System.out.println("The bonus is: " +Bonus );
            } else if (Gain <= 200000) {
                Bonus=(int)(10000 + (Gain - 100000)    * 0.075);
                System.out.println("The bonus is: " + Bonus);
            } else if (Gain <= 400000) {
                Bonus=(int)(10000 + 7500+ (Gain - 200000) * 0.05);
                System.out.println("The bonus is: " + Bonus);
            } else if (Gain <= 600000) {
                Bonus=(int)(10000 + 7500 + 10000+ (Gain - 400000) * 0.03);
                System.out.println("The bonus is: " + Bonus);
            } else if (Gain <= 1000000) {
                Bonus=(int)(10000 + 7500 + 10000 + 6000+ (Gain - 600000) * 0.015);
                System.out.println("The bonus is: " + Bonus);
            } else {
                Bonus=(int)(10000 + 7500 + 10000 + 6000+ 6000 + (Gain - 1000000) * 0.01);
                System.out.println("The bonus is: " + Bonus);
            }
        }
    }

    13,求100000内的完全平方数:

    public class FullSquareNum {
        public static void main(String[] args) {
            for (int i = 0; i < 100000; i++) {

    //一个数的平方根如果是个整数,则该数是完全平方数
                if (Math.sqrt(i + 100) % 1 == 0 && Math.sqrt(i + 268) % 1 == 0) {
                    System.out.println(i + " IS FULL SQURE NUMBER.");
                }
            }
        }
    }

  • 相关阅读:
    基于Antlr4编写DSL
    【整理】ANTLR应用案例 | 在路上
    【整理】ANTLR应用案例 | 在路上
    The ANTLR Parser Generator
    ANTLR4权威参考手册
    ANTLR Examples
    ANTLRWorks: The ANTLR GUI Development Environment
    http://www.cnblogs.com/vowei/archive/2012/08/24/2654287.html
    写一个编译器
    写一个编译器
  • 原文地址:https://www.cnblogs.com/vonk/p/3993314.html
Copyright © 2011-2022 走看看