笔试题目02---贝壳找房2022

笔试题目02---贝壳找房2022

package com.emiteam.study;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class TangerTest {
    public static void main(String[] args) {
        List<Integer> list1 = new ArrayList<Integer>();
        System.out.println("输入有几数");
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        for (int i = 0; i < N; i++) {
            int temp = scanner.nextInt();
            list1.add(temp);
        }
        //进行随机的产生数,进行填充到数组中去
        /*
         * 给定最小数和最大数,产生随机数,随机进行填充到数组中去
         * */
        for (int k = 0; k < list1.size(); k++) {
            int count = 1;
            int temp=list1.get(k);
            int[][] arr = new int[list1.get(k)][list1.get(k)];
            for (int i = 0; i < list1.get(k); i++) {
                for (int j = 0; j < list1.get(k); j++) {
                    if (i == j) {
                        arr[i][j] = count;
                        count++;
                    }
                    if (j > i) {
                        arr[i][j]=arr[i][j-1]+temp;
                    }
                    if(j<i){
                        if(i-j==i){
                            arr[i][j]=arr[i-1][list1.get(k)-1]+1;
                        }else{
                            arr[i][j]=arr[i][j-1]+temp;
                        }
                    }
                }
            }
            for (int i=0;i<arr.length;i++){
                for(int j=0;j<arr.length;j++){
                    System.out.print(arr[i][j]+"\t");
                }
                System.out.println();

            }
        }

    }
    
}

输出结果如下:

笔试题目02---贝壳找房2022

 

上一篇:java int[]如何转换成ArrayList


下一篇:python重点