198k views
18 votes
6. Pattern Displays

Use for loops to construct a program that displays a triangle of Xs on the screen. The

triangle should look like this

X XXXXX

XX XXXX

XXX XXX

XXXX XX

XXXXX X​


please give me answer of this question

User Linell
by
3.6k points

1 Answer

1 vote

Answer:

public static void displayPattern()

{

for (int x = 1; x <= 5; x++)

{

for (int i = 0; i <= 6; i++)

{

if (x == i)

{

System.out.print(" ");

} else {

System.out.print("X");

}

}

System.out.println("");

}

}

User Davidb
by
3.3k points