d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > Help With Simple Java Please > Assignment
Add Reply New Topic New Poll
Member
Posts: 4,635
Joined: May 3 2009
Gold: 1,232.52
Sep 30 2014 01:09pm
Two examples of what the output should look like.

User enters 5
Code
0 * *
1 * *
2 *
3 * *
4 * *


User enters 4
Code
0 * *
1 **
2 **
3 * *


What I've written so far (just an outline) (row is obtained from a scanner)
Code
for(int i = 0; i < row; i++)
{
System.out.print(/*?*/);
for(k = 1; k < /*?*/; k++)
{
if(/*?*/)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println(""); //Returns after each row printed


I really have no idea how to do this. My code is just an outline so far. Any help is appreciated.
Member
Posts: 29,614
Joined: Sep 23 2008
Gold: 0.00
Oct 1 2014 05:51am
Code

for (int i=1; i<=row; i++)
{
for(int j=1; j<=row; j++)
{
if(i==j || j==(row-i+1))
{
System.out.print("*");
}
else
{
System.out.print(' ');
}
}
System.out.println();
}
Go Back To Homework Help Topic List
Add Reply New Topic New Poll