Page 366 - Computer science 868 Class 12
P. 366
Program 4 Write a program to remove the common characters from two strings.
1 import java.util.*;
2 class common
3 {
4 public static void main()
5 {
6 Scanner sc = new Scanner(System.in);
7 String s1,s2,s3="",s4="";
8 int a[],b[],x=0,y=0;
9 int len1,len2;
10 char ch;
11 int i,j;
12 System.out.println("Enter the first sentence:");
13 s1=sc.nextLine().trim();
14 System.out.println("Enter the second sentence:");
15 s2=sc.nextLine().trim();
16 len1=s1.length();
17 len2=s2.length();
18 a=new int[len1];
19 b=new int[len2];
20 for(i= 0;i< len1;i++)
21 {
22 ch=s1.charAt(i);
23 for(j=0;j< len2;j++)
24 {
25 if(ch==s2.charAt(j))
26 break;
27 }
28 if(j!=len2)
29 {
30 a[x++]=i;
31 b[y++]=j;
32 }
33 }
364364 Touchpad Computer Science-XII

