import java.util.Scanner;

 public class Solution
 {
     public static void main(String[] args)
     {
         Scanner input = new Scanner(System.in);
         System.out.print("Enter the size for the matrix: ");
         int size = input.nextInt();

         input.close();

         int[][] array = new int[size][size];
         for(int i = 0; i < size; i++)
         {
             for(int j = 0; j < size; j++)
             {
                 array[i][j] = (int)(Math.random() * 2);
                 System.out.print(array[i][j] + " ");
             }
             System.out.println();
         }

         boolean judgement = true;
         int falseCount = 0;

         for(int i = 0; i < size; i++)
         {
             for(int j = 1; j < size; j++)
                 if(array[i][j] != array[i][j - 1])
                 {
                     judgement = false;
                     falseCount++;
                     break;
                 }
             if(judgement)
                 System.out.println("All " + array[i][0] + "s on row " + i);
             judgement = true;
         }
         if(falseCount == size)
             System.out.println("No same numbers on a row");

         judgement = true;
         falseCount = 0;
         for(int i = 0; i < size; i++)
         {
             for(int j = 1; j < size; j++)
                 if(array[j][i] != array[j - 1][i])
                 {
                     judgement = false;
                     falseCount++;
                     break;
                 }
             if(judgement)
                 System.out.println("All " + array[0][i] + "s on column " + i);
             judgement = true;
         }
         if(falseCount == size)
             System.out.println("No same numbers on a column");

         judgement = true;
         for(int i = 1; i < size; i++)
             if(array[i][i] != array[i - 1][i - 1])
             {
                 judgement = false;
                 break;
             }
         if(judgement)
             System.out.println("All " + array[0][0] + "s on the major diagonal");
         else
             System.out.println("No same numbers on the major diagonal");

         judgement = true;
         for(int i = size - 1; i > 0; i--)
             if(array[i][size - i - 1] != array[i - 1][size - i])
             {
                 judgement = false;
                 break;
             }
         if(judgement)
             System.out.println("All " + array[size - 1][0] + "s on the sub diagonal");
         else
             System.out.println("No same numbers on the sub diagonal");
     }
 }

HW7.14的更多相关文章

  1. Ubuntu 14.04中Elasticsearch集群配置

    Ubuntu 14.04中Elasticsearch集群配置 前言:本文可用于elasticsearch集群搭建参考.细分为elasticsearch.yml配置和系统配置 达到的目的:各台机器配置成 ...

  2. IIC驱动移植在linux3.14.78上的实现和在linux2.6.29上实现对比(deep dive)

    首先说明下为什么写这篇文章,网上有许多博客也是介绍I2C驱动在linux上移植的实现,但是笔者认为他们相当一部分没有分清所写的驱动时的驱动模型,是基于device tree, 还是基于传统的Platf ...

  3. Angular2 Hello World 之 2.0.0-beta.14

    公司现在采用angualrjs开发一些web应用,采用的是angular1,现在angular2已经差不多了,听说最近rc6已经出来了……其实感觉好慢啊!之前也做过一些anglar2的例子,但是没有记 ...

  4. 14门Linux课程,打通你Linux的任督二脉!

    Linux有很多优点:安全.自主.开源--,也正是这些优点使得很多人都在学Linux. 虽说网上有大把的Linux课程资源,但是对很多小白来说网上的课程资源比较零散并不适合新手学习. 正因为此,总结了 ...

  5. deepsooncms在Ubuntu 14.04上部署教程

    deepsooncms在Ubuntu 14.04上部署教程 一.安装mono1.在命令行运行sudo apt-key adv --keyserver keyserver.ubuntu.com --re ...

  6. ubuntu 14.10 lts 64-bits环境下使用Android Studio

    距离google发布android studio 1.0正式版已经两个月左右了.由于一直习惯使用eclipse+ADT的模式,而且曾在windows下试用一次Android Studio预览版,感觉卡 ...

  7. 在 Ubuntu 14.10 中借用 Windows 的字体

    在前一篇随笔中,我详细讨论了字体的分类及用途,也以 Fedora 20 为例,展示了字体配置的思路和方法.我在配置 Fedora 20 系统字体的时候,采用的是一种釜底抽薪的方法,完全抛开了系统原有的 ...

  8. 转-基于NodeJS的14款Web框架

    基于NodeJS的14款Web框架 2014-10-16 23:28 作者: NodeJSNet 来源: 本站 浏览: 1,399 次阅读 我要评论暂无评论 字号: 大 中 小 摘要: 在几年的时间里 ...

  9. CSharpGL(14)用geometry shader渲染模型的法线(normal)

    +BIT祝威+悄悄在此留下版了个权的信息说: CSharpGL(14)用geometry shader渲染模型的法线(normal) +BIT祝威+悄悄在此留下版了个权的信息说: 2016-08-13 ...

随机推荐

  1. RSA (cryptosystem)

    https://en.wikipedia.org/wiki/RSA_(cryptosystem) RSA is one of the first practical实用性的 public-key cr ...

  2. leetcode:Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  3. leetcode:Reverse Bits

    Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...

  4. JavaScript高级程序设计之数据类型

    首先讲讲关于js文件放置的问题,如果把<script>放在head标签处,浏览器会先加载完该处的所有不使用defer属性的js文件再呈现页面的内容(浏览器在遇到body标签时才呈现内容), ...

  5. Java里面instanceof怎么实现的

    开始完全一头雾水呀,后面看了Java指令集的介绍,逐渐理解了. https://www.zhihu.com/question/21574535/answer/18998914 下面这个答案比较直白 你 ...

  6. 解决eclipse-helios中Errors running builder JavaScript Validator的问题

    原文:http://blog.ywxyn.com/index.php/archives/713 解决eclipse-helios中Errors running builder JavaScript V ...

  7. POJ 1745 Divisibility【DP】

    题意:给出n,k,n个数,在这n个数之间任意放置+,-号,称得到的等式的值能够整除k则为可划分的,否则为不可划分的. 自己想的是枚举,将所有得到的等式的和算出来,再判断它是否能够整除k,可是有1000 ...

  8. 转载:NPOI导出到Excel表格

    NPOI开发包下载:http://pan.baidu.com/share/link?shareid=4025220936&uk=2837994235 需要命名空间 using NPOI.HSS ...

  9. UML和模式应用

    引言 Applying UML and Patterns,以一个商店POS系统NextGen和一个掷骰子游戏Monopoly为例,围绕OOA/D的基本原则GRASP,以迭代作为基本方法.以UML为表达 ...

  10. Android隐藏虚拟按键,关闭开机动画、开机声音

    /*********************************************************************** * Android隐藏虚拟按键,关闭开机动画.开机声音 ...