For example, enter a 5 and show this:
* * * * *
* * *
*
My current code is this:
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = 4;
while(num % 2 == 0){
System.out.println("Introduce un numero impar:");
num = in.nextInt();
if (num % 2 == 0){
System.out.println("Has introducido un numero par");
}
}
for (int numFila = 0; numFila < num; numFila++) { //filas
for (int numColumna = 0; numColumna < num*2-1; numColumna++) { //columnas
if (numFila <= numColumna){
System.out.print(" * ");
}else{
System.out.print(" ");
}
}
//Salt de línia per començar un altre fila
System.out.println();
}
}
And what I can show is the following:
* * * * * * *
* * * * * *
* * * * *
No comments:
Post a Comment