package soluzione11092017; public class SoluzioneTestoAMatrice { int[][] m; //costruttore public SoluzioneTestoAMatrice(int[][] m) { this.m = m; } public String toString() { StringBuffer sb = new StringBuffer(); for (int i = 0; i < m.length; i++) { for (int j = 0; j < m[i].length; j++) { sb.append(m[i][j] + " "); } sb.append("\n"); } return sb.toString(); } public boolean triangolare() { if (m.length == m[0].length) { boolean sim = false; for (int i = 1; i < m.length; i++) { sim = false; for (int j = 0; j < m[0].length; j++) { if (j < i) { if (m[i][j] == 0) { sim = true; } else { break; } } } } if (!sim) return false; return true; } return false; } public int somma() { int s = 0; for (int i = 0; i < m.length; i++) { for (int j = 0; j < m[i].length; j++) { s += m[i][j]; } } return s; } public boolean crescente() { boolean cres = false; for (int i = 0; i < m.length - 1; i++) { cres = false; if (m[i][m[i].length - 1] < m[i + 1][0]) { for (int j = 0; j < m[i].length - 1; j++) { if (m[i][j] < m[i][j + 1]) { cres = true; } else { break; } } } else { break; } } if (m.length == 1) {//se ha una sola riga. cres = false; for (int j = 0; j < m[0].length - 1; j++) { if (m[0][j] < m[0][j + 1]) { cres = true; } else { cres = false; } } } if (m[0].length == 1) { cres = false; for (int i = 0; i < m.length - 1; i++) { if (m[i][0] < m[i + 1][0]) { cres = true; } } } if (!cres) return false; return true; } }