当前位置:   article > 正文

找出4*4的矩阵中的最大值,并输出其所在的行列值 。_求4ⅹ4矩中的最大值和最小值,并输出其所在的位置

求4ⅹ4矩中的最大值和最小值,并输出其所在的位置

一、题目描述

找出4*4的矩阵中的最大值,并输出其所在的行列值 。

二、代码实现

import java.util.Scanner;
public class test1 {
	public static void main(String[] args) {
		Scanner f = new Scanner(System.in) ;
		int fn[][]=new int[4][4];
		int num,m,n;
		for(int i=0;i<4;i++) 
			for(int j=0;j<4;j++) {
				fn[i][j] = f.nextInt();
			}
		num=fn[0][0];
		m=n=0;
		for(int i=0;i<4;i++)
			for(int j=1;j<4;j++) {
				if(fn[i][j]>num) {
					num=fn[i][j];
					m=i;
					n=j;
				}
			}
		System.out.println(num);
		System.out.println(m);
		System.out.println(n);
		f.close();
	}
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

三、结果展示

在这里插入图片描述

四、推荐

给大家推荐三款蓝牙耳机,下面的链接可以直接购买:
1、https://item.taobao.com/item.htm?ft=t&id=643733003968
2、https://item.taobao.com/item.htm?ft=t&id=642849670304
3、https://item.taobao.com/item.htm?ft=t&id=639886208479
由于是新开的店铺,购买时联系客服,下单即可享受现金红包。虽然是新店,但是质量是有保证的哦!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/590834
推荐阅读
相关标签
  

闽ICP备14008679号