I have to use nested loops to print the following pattern
*
***
*****
*******
*********
*********
*******
*****
***
*
The lines go 1, 3, 5, 7, 9, 9, 7, 5 ,3 and 1 long and the user choices which character they would like the pattern to be. I have done the user input but with the following code
i have tryed a few different codes to get this to work but i am unable to find any help to get this done on the Internet and textbooks..
The code above puts all the characters in one line
Thanks in advance
Tomas
*
***
*****
*******
*********
*********
*******
*****
***
*
The lines go 1, 3, 5, 7, 9, 9, 7, 5 ,3 and 1 long and the user choices which character they would like the pattern to be. I have done the user input but with the following code
Code:
Scanner scanner = new Scanner(System.in);
//Asks the user what character they would like to use in the pattrern
System.out.println("Please type which charector you would like to use?");
String character = scanner.next();
i have tryed a few different codes to get this to work but i am unable to find any help to get this done on the Internet and textbooks..
Code:
for (int i=1; i<=9; i++)
{
for (int j=1; j<=i; j++)
{
System.out.print(character);
}
for (int k=9; k<=i; k--)
{
System.out.print(character);
}
}
System.out.println();
Thanks in advance
Tomas
Last edited: