HW7.2

import java.util.Scanner;
public class Solution
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int[][] matrix = new int[4][4];
System.out.println("Enter a 4-by-4 matrix row by row: ");
for(int i = 0; i < 4; i++)
for(int j = 0; j < 4; j++)
matrix[i][j] = input.nextInt();
input.close();
System.out.println("Sum of the elements in the major diagonal is " + sumMajorDiagonal(matrix));
}
public static int sumMajorDiagonal(int[][] m)
{
int sum = 0;
for(int i = 0; i < 4; i++)
sum += m[i][i];
return sum;
}
}
HW7.2的更多相关文章
- HW7.18
public class Solution { public static void main(String[] args) { int[][] m = {{1, 2}, {3, 4}, {5, 6} ...
- HW7.17
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW7.16
import java.util.Arrays; public class Solution { public static void main(String[] args) { int row = ...
- HW7.15
public class Solution { public static void main(String[] args) { double[][] set1 = {{1, 1}, {2, 2}, ...
- HW7.14
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW7.13
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW7.12
import java.util.Scanner; public class Solution { public static void main(String[] args) { double[] ...
- HW7.11
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW7.10
public class Solution { public static void main(String[] args) { int[][] array = new int[3][3]; for( ...
- HW7.9
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
随机推荐
- hdu 1233
最小生成树 本来挺简单 一个小错wa了好几遍 /************************************************************************* & ...
- 成功解决Tomcat-JDBC-MySQL乱码
0.MySQL-JDBC驱动文档 官方解释 1.数据库的字符编码和表内字段的编码 在MySQL中数据库的字符编码和表内字段的编码的要指定为utf8(utf8_general_ci) 2.jsp中 pa ...
- Android支付接入(五):机锋网
原地址:http://blog.csdn.net/simdanfeg/article/details/9012083 前边已经陆续跟大家走了一遍运营商和支付宝付费接入,今天跟大家一起看看机锋网的支付接 ...
- http://doc.okbase.net/congcong68/archive/112508.html
http://doc.okbase.net/congcong68/archive/112508.html
- thinkphp 定制错误页面
在前台配置文件里加上: 'TMPL_EXCEPTION_FILE' => '.Public/tpl/error.html',// 异常cuowu页面的模板文件 然后在Public下新建一个tpl ...
- 【转】PostgreSQL IP地址访问配置
原文:http://blog.csdn.net/shuaiwang/article/details/1793294 1.PostgreSQL的安装目录,进入data文件夹,打开postgresql.c ...
- Spring与Struts2整合
Spring与Struts2为什么要整合呢? 把Action实例交给Spring来管理!! 1.单独测试Struts是否添加成功(jar包和配置文件),先单独测试,不要整合之后再测试,容易出问题 we ...
- SGU128 Snake
SGU128,题意是给定N个点,问说能不能形成一个闭环G,要求G经过每个点,且在每个点处都有90度的转角,且不能出现自交. 没想出来,通过这提供的思路,由于每个点处都需要90度的转弯,因此每个点处必然 ...
- [swustoj 679] Secret Code
Secret Code 问题描述 The Sarcophagus itself is locked by a secret numerical code. When somebody wants to ...
- 基于Struts2的用户登录程序
基本步骤: 1.新建Java工程,File>New>Project>Web>Dynamic Web Project,并将工程命名为:Struts2_Demo 2.导入strut ...