Computer Science, asked by hrdpbhamra, 2 months ago

Write a program in java to print the following pattern :-
B
LL
UUU
EEEE​

Answers

Answered by allysia
6

Language:

JAVA

Program:

import java.util.*;  

public class oh

{public static void main(String[] args)

{String a = "BLUE";

for (int i = 0; i < a.length(); i++)

{for (int j = 0; j <= i; j++)

{System.out.print(a.charAt(i));}

System.out.println();}}}

Output:

Consider the attachments.

Explanation:

  • Save "BLUE" in a string variable.
  • Print index+1 times the letter in the same line with a loop.
  • Adds new line with a loop.

Attachments:

Attachments:
Answered by Oreki
10

\textsf{\large \textbf{Algorithm}}

   \text{\textemdash \:\: Getting each letter of the String using \texttt{charAt(int)}.}\\\text{\textemdash \:\: Concatenating letter to itself \texttt{i + 1} times using \texttt{repe\symbol{97}t(int)}.}\\\text{\textemdash \:\: Hence, generating the pattern.}

Attachments:
Similar questions