Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aula.primeira;
- import java.util.Scanner;
- public class Programa {
- public static void main(String[] args) {
- Scanner scn = new Scanner(System.in);
- int[][] matriz = new int[4][4];
- int valor = 0, maior = 0, menor = 1, linha = 0, coluna = 0, linha2 = 0, coluna2 = 0;
- for (int i = 0; i < matriz.length; i++) {
- for (int j = 0; j < matriz.length; j++) {
- System.out.println("Digite um valor para a linha " + (i + 1) + " e coluna " + (j + 1));
- valor = scn.nextInt();
- matriz[i][j] = valor;
- }
- }
- menor = matriz[0][0];
- for (int i = 0; i < matriz.length; i++) {
- for (int j = 0; j < matriz.length; j++) {
- if(matriz[i][j] >= maior) {
- maior = matriz[i][j];
- linha = i;
- coluna = j;
- }
- if(matriz[i][j] <= menor) {
- menor = matriz[i][j];
- linha2 = i;
- coluna2 = j;
- }
- }
- }
- System.out.println("Maior: " + maior + " linha: " + (linha + 1) + " coluna: " + (coluna + 1));
- System.out.println("Menor: " + menor + " linha: " + (linha2 + 1) + " coluna: " + (coluna2 + 1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement