jeudi 25 décembre 2014

About making a X-mas Tree in java [on hold]

This code is supposed to produce this output:


Enter Height of the tree: 5



I
*I*
**I**
***I***
****I****


But it doesn't. How can I fix it?



import java.util.Scanner;
public class RightTriangle {
public static void main(String args[])
{
Scanner keys = new Scanner (System.in);

int high ;
System.out.println("Enter height of the tree");
high = keys.nextInt();


for (int i=0; i< high; i++)
{
for ( int j=0; j<high -1 -i ; j++)
{
System.out.print(" ");
}

for (int k=0; k<i*2+1; k++)
{
System.out.print("*");
}
System.out.println ();
}
}
}

Aucun commentaire:

Enregistrer un commentaire