Advertisements
Advertisements
Question
Write a program in Java to display the following pattern:
A
ab
ABC
abcd
ABCDE
Answer in Brief
Solution
public class Q12a{
public static void main(String args[])
{
String s = "abcde";
System.out.println("\n\n");
for (int i = 0; i <= 4; i++)
{ for (int j = 0; j <= i; j++)
{ if (i % 2 = 0)
System.out.print(Character.toUpperCase(s.charAtG)));
else
System.out.print(Character.toLowerCase(s.charAtU)));
}
System. out. println();
}
shaalaa.com
Is there an error in this question or solution?
Chapter 2: Library Classes - EXERCISES [Page 180]