public class Keys {

    public static void main(String[] args) {
        //声明列表
        char key1[] = {'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'};
        char[] key2 =  {'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'};
        char key3[]= new char[] {'Z', 'X', 'C', 'V', 'B', 'N', 'M'};
        
        //列表长度
        System.out.println("key1长度:"+key1.length);
        System.out.println("key2长度:"+key2.length);
        System.out.println("key3长度:"+key3.length);
    }
}

 

import javax.jws.soap.SOAPBinding;
import java.util.Arrays;
import java.util.Scanner;

public class Ticket {
  
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int zw[][] = new int[9][4];
//        列表填充为1
        for (int i = 0; i < zw.length; i++) {
            Arrays.fill(zw[i], 1);
        }
        do {
            System.out.println("行列如下:");
            for (int i = 0; i < zw.length; i++) {
                for (int j = 0; j < zw[i].length; j++) {
                    System.out.print(zw[i][j] + "\t");
                }
                System.out.println();
            }

            System.out.println("请输入行:");
            int h = sc.nextInt();
            System.out.println("请输入列:");
            int l = sc.nextInt();

            if (h >= 1 && h <= 9 && l >= 1 && l <= 4) {
                zw[h - 1][l - 1] = 0;
            } else if (h == 0 || l == 0) {
                System.out.println("over");
                break;
            } else {
                System.out.println("行数or列数错误,请重新输入!(规则:1~9)");
            }

        } while (true);
    }
}

 

public class SwapRC {// 交换二维数组的行列数据

    public static void main(String[] args) {
        /*
        列表行和列交换位置
        * */
        System.out.println("原列表:");

        int[][] list =  { { 8, 75, 23,67 }, { 21, 55, 34,77 }, { 15, 23, 20,88 },{7,8,9,0} };

        for (int i = 0; i < list.length; i++) {
            /*打印原列表*/
            for (int j = 0; j < list[i].length; j++) {
                System.out.print(list[i][j]+"\t");
            }
            System.out.println();
        }


        for (int i = 0; i < list.length; i++) {
            /*行列交换位置*/
            int temp =0;
            for (int j = i+1; j < list[i].length; j++) {
                temp = list[i][j];
                list[i][j]=list[j][i];
                list[j][i] = temp;
            }
        }


        System.out.println("行列交换后列表:");
        for (int i = 0; i < list.length; i++) {
            /*打印交换后列表*/
            for (int j = 0; j < list[i].length; j++) {
                System.out.print(list[i][j]+"\t");
            }
            System.out.println();
        }

    }
}
import java.util.Arrays;

public class YangHui {// 杨辉三角算法的实现
    public static void main(String[] args) {
//        长度为10的二维数组
        int[][] list = new int[10][];
        for (int i = 0; i < 10; i++) {
//            二维数组的列数
            list[i] = new int[i + 1];
//            杨辉数值:第一列和最后一列均为1
            list[i][0] = 1;
            list[i][i] = 1;
//            杨辉数值:从第3行起,规律赋值
            if (i >= 2) {
                for (int j = 1; j < (list[i].length - 1); j++) {
                    list[i][j] = list[i - 1][j - 1] + list[i - 1][j];
                }
            }
        }

//        打印
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[i].length; j++) {
                System.out.print(list[i][j] + "\t");
            }
            System.out.println();
        }
    }
}

 

posted on 2022-06-27 20:10  jxba  阅读(80)  评论(0编辑  收藏  举报