• 【笔试题】简单的两道笔试题(1、打印杨辉三角;2、三个数排序)


    笔试题 简单的两道笔试题(1、打印杨辉三角;2、三个数排序)
    1、打印杨辉三角

    import java.util.Scanner;
    public class MyYanghuiTriangle {
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            int row = scan.nextInt();
            int[][] nums = new int[row][];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = new int[i + 1];
                for (int s = 0; s < nums.length - 1 - i; s++) {
                    System.out.print("  ");
                }
                for (int j = 0; j < nums[i].length; j++) {
                    if (j == 0 || j == nums[i].length - 1) {
                        nums[i][j] = 1;
                    } else {
                        nums[i][j] = nums[i-1][j] + nums[i - 1][j - 1];
                    }
                    System.out.printf("%4d", nums[i][j]);
                }
                System.out.println();
            }
            scan.close();
        }
    }
    
    

    2、三个数排序(输入3个数a,b,c,按大小顺序输出。)

    import java.util.Scanner;
    public class ThreeSort {
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            int a = scan.nextInt();
            int b = scan.nextInt();
            int c = scan.nextInt();
            if(a<b) {
                int temp = a;
                a = b;
                b = temp;
            }
            if(a<c) {
                int temp = a;
                a = c;
                c = temp;
            }
            if(b<c) {
                int temp = b;
                b = c;
                c = temp;
            }
            scan.close();
            System.out.print("从大到小的顺序输出:");
            System.out.println(a+" "+b+" "+c);
        }
    }
    

  • 相关阅读:
    Spring IOC 源码解析
    spring AOP之代理模式
    HashMap的工作原理

    数据结构 (1)----线性表
    php简单的查找当前目录下的非法文件
    Js中Prototype、__proto__、Constructor、Object、Function关系介绍 ,JS原型
    js的变量,变量作用域,作用域链
    JS的类型转换
    sql 的join
  • 原文地址:https://www.cnblogs.com/hgnulb/p/9469404.html
Copyright © 2020-2023  润新知