I need to write a program in Eclipse that displays "*" in a line of seven and then takes one off each line while also using nested loops.
I've tried using examples that the teacher provided and then adapting it to use an "*".
This is the code I've been trying to use
public class ForWhileLoopsPractice {
public static void main(String[] args) {
int rows = 7;
int asterisk = '*';
for(int i = asterisk; i <= rows; i++ ) {
for(int j = asterisk; j >= i; j--) {
System.out.print(j + " ");
}
System.out.println(" ");
}
}
}
This just terminates automatically and I don't think it will even go in the right direction if it works.
The end result should look like
"*******"
"******"
"*****"
"****"
"***"
"**"
"*"
without the quotes around each one and just the asterisk but I have been unable to produce anything close to this.
Thank you for all the help so far. Now my code looks like this
int rows = 7;
for(int i = 0; i < rows; i++ )
{
for(int j = 0; j < rows; j++)
{
System.out.print("*");
}
System.out.println("*");
}
Output is now
********
********
********
********
********
********
********
I just need to find a way to subtract one from each row.
Thank you to @an3rror, the solution ended up being
int rows = 7;
int columns = 7;
for(int i = 0; i < rows; i++ )
{
for(int j = 0; j < columns; j++)
{
System.out.print("*");
}
System.out.println();
columns--;
}
Thank you everyone who replied for giving me tips, without just outright saying the answer, and explaining what each thing was and why it was that way.