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

Java Example – Print an inverted triangle

Java Example – Print an inverted triangle

Java Examples Java Examples

Print an inverted triangle.

Example

public

class

InvertedTriangle

{

public

static

void

main

(

String

[

]

args

)

{

//

Print an inverted triangle

for

(

int

m

=

1

;

m

<=

4

;

m

++

)

{

//

Print spaces

for

(

int

n

=

0

;

n

<=

m

;

n

++

)

{

System

.

out

.

print

(

"

"

)

;

}

//

Print *

for

(

int

x

=

1

;

x

<=

7

2

(

m

1

)

;

x

++

)

{

System

.

out

.

print

(

"

"

)

;

}

System

.

out

.

println

(

)

;

}

}

}

Output result:


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

Java Examples Java Examples