package tutorialJava.examenes.examen20241122;

import tutorialJava.UtilsArrays;

public class EjB_GenerarMatrizDesdeArrayString {

	public static void main(String[] args) {
		String p[] = new String[] {"hola", "adios", "rojo", "azul"};

		char m[][] = new char[p.length][maximaLongitdPalabraEnArray(p)];
		
		for (int i = 0; i < m.length; i++) {
			for (int j = 0; j < m[i].length; j++) {
				if (j < p[i].length()) {
					m[i][j] = p[i].charAt(j);
				}
				else {
					m[i][j] = '_';
				}
			}
		}
		
		UtilsArrays.imprimeMatriz(m);
	}

	
	public static int maximaLongitdPalabraEnArray(String a[]) {
		int mayor = a[0].length();
		for (int i = 1; i < a.length; i++) {
			if (a[i].length() > mayor) {
				mayor = a[i].length();
			}
		}
		return mayor;
	}
}
