I'm trying to do an exercise where the user must enter the number of columns and the character he wants to appear. I'm a little messed up when it comes to doing it. I leave the statement:
Make a program using loops that shows the following figure on the screen, asking the user in advance how many rows you want to display and which character you want to use (for example, *). You must perform exception handling.
Code:
public class ejercicio3 {
public static void main(String[] args) {
try{
Scanner teclado;
int Ncolumnas;
String caracter;
System.out.print("Introduce cuantas filas deseas mostrar: ");
teclado = new Scanner(System.in);
Ncolumnas = teclado.nextInt();
System.out.print("Introduce un caracter: ");
teclado = new Scanner(System.in);
caracter = teclado.next();
for(int i=1;i>Ncolumnas; i++){
i++;
if (Ncolumnas>0){
System.out.print("Introduce un caracter: " + (caracter + Ncolumnas));
}else{
System.out.print("Error ");
}
}
}catch(Exception e){
System.out.println("Error, no has introducido un carácter");
}
}
}
When I do this, the result does not appear, because obviously, there is something I am doing wrong.
PS: Rookie in sight.