zoukankan      html  css  js  c++  java
  • 【笔试题】简单的两道笔试题(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);
        }
    }
    

  • 相关阅读:
    Educational Codeforces Round 80 (Rated for Div. 2)
    寒假集训
    HDU-4609 3-idiots
    部分分式展开法
    线性同余方程组
    爬取哔哩哔哩python搜索结果
    数据可视化练习题
    python正则表达式
    git的安装和基础知识
    python学习计划
  • 原文地址:https://www.cnblogs.com/hgnulb/p/9469404.html
Copyright © 2011-2022 走看看