第八章第十四题(探讨矩阵)(Discussion matrix)

第八章第十四题(探讨矩阵)(Discussion matrix)

  • **8.14(探讨矩阵)编写程序提示用户输入一个方阵的长度,随机的在矩阵中填入0和1,打印这个矩阵,然后找到,整行,整列或者对角线都是0或1的行、列和对角线。下面是这个程序的一个运行示例:
    Enter the size for the matrix: 4
    0 1 0 0
    1 0 0 0
    0 0 0 1
    0 0 1 1
    no same numbers on a row
    no same numbers on a column
    Na same numbers on the major diagonal
    All 0s on the sub-diagonal
    **8.14(Discussion matrix)Write a program to prompt the user to enter the length of a square matrix, randomly fill in 0 and 1 in the matrix, print the matrix, and then find the row, column and diagonal line with 0 or 1 as the whole row, column or diagonal. Here is a running example of this program:
    Enter the size for the matrix: 4
    0 1 0 0
    1 0 0 0
    0 0 0 1
    0 0 1 1
    no same numbers on a row
    no same numbers on a column
    Na same numbers on the major diagonal
    All 0s on the sub-diagonal

  • 参考代码:

    package chapter08;
    
    import java.util.Scanner;
    
    public class Code_14 {
         
        public static void main(String args[]){
         
            Scanner cin = new Scanner(System.in);
            System.out.print("Enter the size for the matrix: ");
            int size = cin.nextInt();
            int[][] matrix = new int[size][size];
            for(int i = 0; i < size; ++i){
         
                for(int j = 0; j < size; ++j){
         
                    matrix[i][j] = (((int)System.currentTimeMillis()) / (i 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值