write a program to print the following pattern (IN java)
Attachments:
Answers
Answered by
3
String name = "BLUE";
for(int i = 0 ; i<name.length();i++){
char c = name.charAt(i);
for(int y = 0;y <i+1;y++)
{
System.out.print(c);
}
System.out.print("/n");
}
for(int i = 0 ; i<name.length();i++){
char c = name.charAt(i);
for(int y = 0;y <i+1;y++)
{
System.out.print(c);
}
System.out.print("/n");
}
QGP:
By the way, just a correction. The escape sequence for new line is "\n"
Answered by
4
public class Pattern
{
public static void main(String[] args)
{
String str = "BLUE";
for(int i=0;i<4;i++)
{
char ch = str.charAt(i);
for(int j=0;j<=i;j++)
{
System.out.print(ch);
}
System.out.println();
}
}
}
{
public static void main(String[] args)
{
String str = "BLUE";
for(int i=0;i<4;i++)
{
char ch = str.charAt(i);
for(int j=0;j<=i;j++)
{
System.out.print(ch);
}
System.out.println();
}
}
}
Similar questions