Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java Example – Print a parallelogram

Java Example – Print a parallelogram

Java Examples Java Examples

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

.

print

(

"

"

)

;

}

//

Inner loop prints one * each time

for

(

int

k

=

1

;

k

<=

5

;

k

++

)

{

System

.

out

.

print

(

"

"

)

;

}

System

.

out

.

println

(

)

;

}

}

}

Output result:


    *****
   *****
  *****
 *****
*****

Java Examples Java Examples