Advertisements
Advertisements
प्रश्न
Write a programme to accept a word (say, BLUEJ) and display the pattern:
- B L U E J
B L U E
B L U
B L
B - J
E E
U U U
L L L L
B B B B B - B L U E J
L U E J
U E J
E J
j
कोड लेखन
उत्तर
//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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?