Page 428 - CA_Blue( J )_Class10
P. 428
10 System.out.print("Enter a sentence : ");
11 str=sc.nextLine();
12 System.out.print("Enter character to replace : ");
13 chr=sc.next().charAt(0);
14 System.out.print("Enter new character : ");
15 chi=sc.next().charAt(0);
16 l=str.length();
17 for(i=0;i<l;i++)
18 {
19 ch=str.charAt(i);
20 if(ch==chr)
21 ch=chi;
22 newstr=newstr+ch;
23 }
24 System.out.println("Original String : "+str);
25 System.out.println("Replaced string : "+newstr);
26 }
27 }
To input full name of a person and print its abbreviated form.
Program 4 Example: Subhas Chandra Bose
Output: S. C. Bose
1 import java.util.*;
2 class abbreviate
3 {
4 public static void main()
5 {
6 Scanner sc= new Scanner(System.in);
7 String str, newstr ="";
8 int i, l,sp;
9 char ch;
10 System.out.print("Enter name: ");
11 str=sc.nextLine();
12 str= " "+str;
13 l=str.length();
426426 Touchpad Computer Applications-X

