JAVA Given 2 strings that have all letters in common except

 *******************JAVA****************** Given 2 strings that have all letters in common except one, find the letter that is the odd one out.   Hint: Check out the Java String class documentation. Is there String method that can make this easy?  Example Output:         Enter 2 words:   chase            arches            The extra letter is r  Name your class Hw6pr5 and your file Hw6pr5.java 

Solution

import java.util.Scanner;

public class Hw6pr5

{

public static void main(String args[])

{

Scanner s=new Scanner(System.in);

private String str1;

private String str2;

int n1=str1.length();

int n2=str2.length();

int x1,x2;

if(Math.abs(n1-n2)==1)

if(n1>n2)

{

x1=n1;x2=n2;

}

if(n1<n2)

{

x1=n2;x2=n1;

String temp=str1;

str1=str2;

str2=str1;

}

else

System.out.println(\"invalid input\");

for(int i=0;i<x1;i++)

{

for(int j=0;j<x2;j++)

{

if(str1[i]!=str2[j])

{

System.out.println(\"extra value : \"+str1[i]);

break;

}

}

}

}

}

 *******************JAVA****************** Given 2 strings that have all letters in common except one, find the letter that is the odd one out. Hint: Check out
 *******************JAVA****************** Given 2 strings that have all letters in common except one, find the letter that is the odd one out. Hint: Check out

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site