English

Write a programme to accept a word (say, BLUEJ) and display the pattern: B L U E JB L U EB L UB LB JE EU U UL L L LB B B B B B L U E JL U E JU E JE Jj - Computer Applications

Advertisements
Advertisements

Question

Write a programme to accept a word (say, BLUEJ) and display the pattern: 

  1. B L U E J
    B L U E
    B L U
    B L
    B
  2. J
    E E
    U U U
    L  L  L  L
    B B B B B
  3. B L U E J
    L U E J
    U E J
    E J
    j
Code Writing

Solution

//INPUT : BLUEJ
import java.util.*;
class SQ20{
public static void main(String hg[])
{
int i, j, len;
String s;
Scanner ob = new Scanner(System.in);
System.out.println("Enter a string");
s = ob.next();
len = s.length(); // position of last character
System.out.println("\n***Pattern] ***");
for (i = len; i > 0; i--) // OUTER LOOP—>rows
{
for (j = 0; j < i; j++) // INNER LOOP—>columns
System.out.print(" " + s.charAt(j));
System.out.println(); 
}

System.out.println("\n***Pattern2***");
for (i = len; i >= 0: i--)
{
for (j = len-1; j >= i; j--)
System.out.print(" " + s.charAt(i));
System. out.println();
}
System.out.println("\n***Pattern3***");
for (i = 0; i < len; i++)
{
for (j = i; j < len; j++)
System.out.print(" " + s.charAt(j));
System.out.println();
}}
shaalaa.com
  Is there an error in this question or solution?
Chapter 4: String Handling - EXERCISES [Page 292]

APPEARS IN

Avichal Computer Applications [English] Class 10 ICSE
Chapter 4 String Handling
EXERCISES | Q IX. 20. | Page 292
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×