Java Example – Print a parallelogram
Output a parallelogram.
Example
public
class
Parallelogram
{
public
static
void
main
(
String
[
]
args
)
{
//
Outer loop prints one * each time
for
(
int
i
=
1
;
i
<=
5
;
i
++
)
{
//
Fill spaces
for
(
int
j
=
1
;
j
<=
5
i
;
j
++
)
{
System
.
out
.
(
"
"
)
;
}
//
Inner loop prints one * each time
for
(
int
k
=
1
;
k
<=
5
;
k
++
)
{
System
.
out
.
(
"
"
)
;
}
System
.
out
.
println
(
)
;
}
}
}
Output result:
*****
*****
*****
*****
*****
Java Examples