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

Java Example – Print a rectangle

Java Example – Print a rectangle

Java Examples Java Examples

Output a rectangle.

Example

public

class

Rect

{

public

static

void

main

(

String

[

]

args

)

{

//

Outer loop outputs one row of * each time

for

(

int

i

=

1

;

i

<=

5

;

i

++

)

{

System

.

out

.

print

(

"

"

)

;

//

Inner loop outputs one * each time

for

(

int

j

=

1

;

j

<=

5

;

j

++

)

{

System

.

out

.

print

(

"

"

)

;

}

System

.

out

.

println

(

)

;

}

}

}

Output result:


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

Java Examples Java Examples