当前位置: 首页 > wzjs >正文

用flash做的经典网站网站上的图片格式怎么做

用flash做的经典网站,网站上的图片格式怎么做,网站建设需要注意的,不允许做企业网站目录 Day 7:Java 的数组与矩阵元素相加 一、基本知识 二、矩阵的建立与基本计算 三、代码及测试 拓展:Arrays类详解 小结 Day 7:Java 的数组与矩阵元素相加 Task: 矩阵的赋值.二重循环. 一、基本知识 在学习 Java 中的数组与矩…

目录

Day 7:Java 的数组与矩阵元素相加

 一、基本知识

 二、矩阵的建立与基本计算

三、代码及测试

拓展:Arrays类详解

小结


Day 7:Java 的数组与矩阵元素相加

Task:

  • 矩阵的赋值.
  • 二重循环.

 一、基本知识

        在学习 Java 中的数组与矩阵前,我们需要以下两个基本知识:

  • 动态创建
  • Arrays 类

        这部分的知识点请参考相关的 Java 专题补充:
        

 二、矩阵的建立与基本计算

        本博客中,将用代码实现两种基本的矩阵计算:全元素求和,基本加法

1. 矩阵元素总和

        同样的,我们依旧把这个功能封装为单独的函数

	/************************ Sum the elements of a matrix.* * @param paraMatrix The given matrix.* @return The sum of all its elements.**********************/public static int matrixElementSum(int[][] paraMatrix) {int resultSum = 0;for (int i = 0; i < paraMatrix.length; i++) {for (int j = 0; j < paraMatrix[0].length; j++) {resultSum += paraMatrix[i][j];} // Of for j} // Of for ireturn resultSum;}// Of matrixElementSum

        代码不多做解释,通过双层 for 循环即能遍历矩阵中的所有元素。唯一值得注意的是,我们该如何去理解通过数组组成的矩阵?
        首先矩阵的高其实就是矩阵的一维部分,一个矩阵在计算机中可以看做是“一维数列”的数组,把这个数组的元素纵向放置就构成了我们视觉可见的一个“矩形”的数字阵列。而这个“一维数列”的数组的长度自然就是这个阵列的纵向长度,也就是高,是把这个数组的元素纵向放置可以排的行数。因此:

paraMatrix.length

        就是矩阵的宽,或者说行数。
        同理,“一维数列”的数组中的每个元素都是一个一维数列,每个数列的长度就构成了矩阵的长,或者说列数。实际代码中,我们取出“一维数列”的数组的第一个元素,也就是矩阵的第一行,并求这一个行的长度即可:

paraMatrix[0].length

        具体遍历的话,基本所有语言的二维存储都是采用行优先的存储,而普遍的遍历都是先行后列的遍历思想,因此这一点不再赘述。

2. 矩阵相加

        一个优秀的程序是需要有自我报错能力的,比如这里的非法矩阵相加。
        矩阵相加的话需要符合线性代数中矩阵计算的一个基本要求——即相加的双方矩阵必须是同型的。因此注意对于非法情况的判断。

	/************************ Add two matrices. Attention: No error check is provided at this moment.* * @param paraMatrix1 The first matirx.* @param paraMatrix2 The second matrix. It should have the same size as the*                    first one's* @return The addition of these matrices.**********************/public static int[][] matrixAddition(int[][] paraMatrix1, int[][] paraMatrix2) {if(paraMatrix1.length!=paraMatrix2.length || paraMatrix1[0].length!=paraMatrix2[0].length) {System.out.println("Error! Two matrixs must have same height and width! ");}int[][] resultMatrix = new int[paraMatrix1.length][paraMatrix1[0].length];for (int i = 0; i < paraMatrix1.length; i++) {for (int j = 0; j < paraMatrix1[0].length; j++) {resultMatrix[i][j] = paraMatrix1[i][j] + paraMatrix2[i][j];} // Of for j} // Of for ireturn resultMatrix;}// Of matroxAddition

三、代码及测试

package basic;import java.util.Arrays;/*** This is the seventh code. Names and comments should follow my style strictly.** @author: Changyang Hu joe03@foxmail.com* @date created: 2025-05-09*/
public class MatrixAddition {/************************* @Title: main* @Description: The entrance of the program.** @param args Not used now.* @return void************************/public static void main(String args[]) {matrixElementSumTest();matrixAdditionTest();}// Of main/************************* * @Title: matrixElementSun* @Description: Sum the elements of a matrix** @param paraMatrix The given matrix* @return * @return int************************/public static int matrixElementSum(int[][] paraMatrix) {int resultSum = 0;for (int i = 0; i < paraMatrix.length; i++) {for (int j = 0; j < paraMatrix[0].length; j++) {resultSum += paraMatrix[i][j];} // Of for j} // Of for ireturn resultSum;}// Of matrixElementSum/*** ********************** @Title: matrixElementSumTest* @Description: Unit test for respective method.* * @return void **********************/public static void matrixElementSumTest() {int[][] tempMatrix = new int[3][4];for (int i = 0; i < tempMatrix.length; i++) {for (int j = 0; j < tempMatrix[0].length; j++) {tempMatrix[i][j] = i * 10 + j;} // Of for j} // Of for iSystem.out.println("The matrix is: \r\n" + Arrays.deepToString(tempMatrix));System.out.println("The matrix element sum is: " + matrixElementSum(tempMatrix) + "\r\n");}// Of matrixElementSumTest/*** ********************** @Title: matrixAddition* @Description: Add two matrices. Attention: NO error check is provided at this moment.** @param paraMatrix1	The first matrix.* @param paraMatrix2	The second matrix. It should have the same size as*                    	the first one's.* @return The addition of these matrices.* @return int[][] **********************/public static int[][] matrixAddition(int[][] paraMatrix1, int[][] paraMatrix2) {int[][] resultMatrix = new int[paraMatrix1.length][paraMatrix1[0].length];for (int i = 0; i < paraMatrix1.length; i++) {for (int j = 0; j < paraMatrix1[0].length; j++) {resultMatrix[i][j] = paraMatrix1[i][j] + paraMatrix2[i][j];} // Of for j} // Of for ireturn resultMatrix;}// Of matrixAdditon/*** ********************** @Title: matrixAdditionTest* @Description: Unit test for respective method.* * @return void **********************/public static void matrixAdditionTest() {int[][] tempMatrix = new int[3][4];for (int i = 0; i < tempMatrix.length; i++) {for (int j = 0; j < tempMatrix[0].length; j++) {tempMatrix[i][j] = i * 10 + j;} // Of for j} // Of for iSystem.out.println("The matrix is; \r\n" + Arrays.deepToString(tempMatrix));int[][] tempNewMatrix = matrixAddition(tempMatrix, tempMatrix);System.out.println("The new matrix is: \r\n" + Arrays.deepToString(tempNewMatrix));}// Of matrixAdditionTest}// Of class MatricAddtion

运行结果如下:

拓展:Arrays类详解

【Java 专题补充】Arrays类详解-CSDN博客


小结

        java提供了许多的库,而这些库方法能对一些基本的操作进行优化。本篇的矩阵相加并不是很难的一部分,但是却暗示了不同语言的实现思路,不同语言对于数组的声明以及遍历的策略。
        另外本文提到的矩阵也是一种非常重要的数据结构,虽然许多语言对于矩阵实现封装库信息很有限(除开matlab这种从矩阵角度出发的编程语言),但是其包含的算法却仍然非常丰富。在 C,C++,java,python 中都有对应的用于处理矩阵数据的库,这些能为我们提供极大的便捷。因此基于基础的二维数组数据模拟复杂的矩阵算法能极大锻炼我们的代码思维与对矩阵之中包含的数学逻辑的理解。但需要注意的是,在使用这些现成的函数时,要有意识的去理解背后的原理,否则只会成为空有其表的调包侠。
        同时,对于图像的颜色,在计算机中我们常用0-255的数值来表示。所以,一张图像实际上就是一个二维矩阵。这个基础使得矩阵在计算机视觉中的应用中也扮演着关键作用,其中延伸出来的图像处理算法也在继续为后世服务。


文章转载自:

http://3qUvETz8.wcrcy.cn
http://VPHXSfnK.wcrcy.cn
http://HtdAkI4m.wcrcy.cn
http://Dtuw2MwX.wcrcy.cn
http://bHK0GP0N.wcrcy.cn
http://BjR1vxv4.wcrcy.cn
http://6YQdtR1y.wcrcy.cn
http://lm3NNgRn.wcrcy.cn
http://p5CqpFXt.wcrcy.cn
http://wyywGmQZ.wcrcy.cn
http://tFr2vncg.wcrcy.cn
http://JuNdlAPD.wcrcy.cn
http://6feRqOXJ.wcrcy.cn
http://WKTnnC1s.wcrcy.cn
http://ypyDi8R5.wcrcy.cn
http://wgpxkrM3.wcrcy.cn
http://sMIbrxeY.wcrcy.cn
http://rFVguwvH.wcrcy.cn
http://8LkRKfa9.wcrcy.cn
http://h2U55jL6.wcrcy.cn
http://cKku87XM.wcrcy.cn
http://7VOp5ALZ.wcrcy.cn
http://bRuPCNFj.wcrcy.cn
http://TJyBdLrb.wcrcy.cn
http://sKBkxcwu.wcrcy.cn
http://i70Xzl1P.wcrcy.cn
http://dQ14qeE1.wcrcy.cn
http://0exJXRKG.wcrcy.cn
http://N2TdtajE.wcrcy.cn
http://l0B87R3M.wcrcy.cn
http://www.dtcms.com/wzjs/745746.html

相关文章:

  • 黄岛做网站哪家好公司网站规划案例
  • 建设银行临夏分行网站asp.net mvc 网站开发
  • 网站建设基础心得邯郸市出租房屋信息网
  • axrue怎么做网站的原型图网络营销策划步骤
  • 图片在线制作网站yellow的视频播放
  • 建立网站外链常用的渠道有哪些wordpress连接微博源码
  • 国内设计网站公司1771wan网页游戏
  • 网站建设专家如何选汕头网站推广排名
  • 西安网站建设服务商推广普通话奋进新征程宣传语
  • 网站搭建公司排行学做网站论坛插件
  • 蓝牙音箱东莞网站建设直播平台开发多少钱
  • 汽车行业网站建设方案达州市住房和建设厅网站
  • 虚拟主机网站怎么上传文件遨游建站
  • 潍坊市房屋和城乡建设局网站网站开发的收入
  • 建设网站如何加入搜索网站开发vs2015是什么
  • 网站建设全屏广州网站建设全包
  • 网站服务器有哪些种类给个网站可以在线
  • 网站建设与维护 出题狮山公司网站建设
  • 门户网站改造方案阿里巴巴每平每屋设计家官网
  • 如何做网站赚钱6毕业生就业推荐表模板网站开发
  • 商水县建设局网站网站构造下拉列表怎么做
  • 统计网站建设程序网站开发基本要求
  • 无域名网站 能否被百度天津微信网站
  • 苏宁易购的网站建设企业网站建设任务书
  • wordpress建站图片效果网站建设哪家合适
  • 求免费的那种网站有哪些海口专业网站制作策划
  • 厦门网站建设定制多少钱如何查看网站是谁建设的
  • jq效果较多的网站有些电影网站是怎么做的
  • 美乐乐 网站建设网站建设要会英语吗
  • 做房产抵押网站需要什么手续费广州中国建设银行网站首页