Page 434 - CA_Blue( J )_Class10
P. 434
17 System.out.println(extwd);
18 }
19 }
20 }
To create a menu-driven program to input a word and using user’s choice print the following
Program 10
pattern.
Input: COMPUTER
Choice 1: Choice 2:
C R
CO ER
COM TER
COMP UTER
COMPU PUTER
COMPUT MPUTER
COMPUTE OMPUTER
COMPUTER COMPUTER
1 import java.util.*;
2 class pattern_choice
3 {
4 public static void main()
5 {
6 Scanner sc= new Scanner(System.in);
7 String wd,extwd;
8 int i,l,j,ch;
9 System.out.print("Enter a word : ");
10 wd=sc.next();
11 wd=wd.toUpperCase();
12 l=wd.length();
13 System.out.println("Enter 1 for pattern 1 / 2 for pattern 2 ");
14 ch=sc.nextInt();
15 switch(ch)
16 {
17 case 1:
18 for(i=0;i<l;i++)
19 {
20 extwd=wd.substring(0,i+1);
21 System.out.println(extwd);
432432 Touchpad Computer Applications-X

