Page 253 - computer science (868) class 11
P. 253
Choice 1: Choice 2:
I A
IN AI
IND AID
INDI AIDN
INDIA AIDNI
Ans. import java.util.*;
class pattern_choice
{
public static void main()
{
Scanner sc= new Scanner(System.in);
String wd, extwd;
int i, l, j, ch;
System.out.print("Enter a word: ");
wd=sc.next();
wd=wd.toUpperCase();
l=wd.length();
System.out.println("Enter 1 for pattern 1 / 2 for pattern 2 ");
ch=sc.nextInt();
switch(ch)
{
case 1:
for(i=0; i<l; i++)
{
extwd=wd.substring(0,i+1);
System.out.println(extwd);
}
break;
case 2:
for(i=l-1; i>=0; i--)
{
extwd="";
for(j=i; j<l; j++)
{
extwd=extwd+wd.charAt(j);
}
System.out.println(extwd);
}
break;
default: System.out.println("Wrong choice");
}
}
}
Unsolved Questions
A. Tick ( ) the correct answer:
1. Which of the following methods is used to join the strings together?
a. concat() b. append()
c. concatenate() d. Both a and b
251
Strings 251

