Advertisement
Guest User

7

a guest
Nov 17th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. package aula.primeira;
  2. import java.util.Scanner;
  3. public class Programa {
  4. public static void main(String[] args) {
  5. Scanner scn = new Scanner(System.in);
  6. int[][] matriz = new int[4][4];
  7. int valor = 0, maior = 0, menor = 1;
  8. for (int i = 0; i < matriz.length; i++) {
  9.  
  10. for (int j = 0; j < matriz.length; j++) {
  11. System.out.println("Digite um valor para a linha " + (i + 1) + " e coluna " + (j + 1));
  12. valor = scn.nextInt();
  13. matriz[i][j] = valor;
  14. }
  15. }
  16. menor = matriz[0][0];
  17. for (int i = 0; i < matriz.length; i++) {
  18. for (int j = 0; j < matriz.length; j++) {
  19. if(matriz[i][j] > maior) {
  20. maior = matriz[i][j];
  21. }
  22. if(matriz[i][j] < menor) {
  23. menor = matriz[i][j];
  24. }
  25.  
  26. }
  27. }
  28. System.out.println("Maior: " + maior);
  29. System.out.println("Menor: " + menor);
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement