Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

import java.util.

Scanner;
public class Incommon2 {

public static void main(String[] args) {


Scanner kb = new Scanner (System.in);
System.out.print("Enter sentence 1: ");
String sen1 = kb.nextLine();
String Usen1 = sen1.toUpperCase();
System.out.print("Enter sentence 2: ");
String sen2 = kb.nextLine();
String Usen2 = sen2.toUpperCase();
String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
System.out.print("The letterers in common area: ");
for(int i=0;i<alpha.length();i++)
{
int x = 0;
for(int j=0;j<Usen1.length();j++)
{
if(alpha.charAt(i)==Usen1.charAt(j))
{
x++;
j = Usen1.length();
}
}
for(int k=0;k<Usen2.length();k++)
{
if(alpha.charAt(i)==Usen2.charAt(k))
{
x++;
k = Usen2.length();
}
if(x==2)
{
System.out.print(alpha.charAt(i)+" ");
}
}
}
}
}

You might also like