Computing Magazine

Compares Two Words and Tells You How Many of the Letters Are Different.

Posted on the 22 April 2012 by In7rud3r
<a href="http://www.yesadvertising.com">affiliate marketing</a>

// This program reads in two words and says how many of the letters are different.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class SimilarWords
{
public static void main(String[] pArgs) throws IOException
{
final BufferedReader tKeyboard = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Type in a string: ");
System.out.flush();
final String tString1 = tKeyboard.readLine();

System.out.print(“Type in another string: “);
System.out.flush();
final String tString2 = tKeyboard.readLine();

final int tStringLength = tString1.length();
int tCounter=0;

for (int tCharNumber = 0; tCharNumber{
final char tChar = tString1.charAt(tCharNumber);

if (tString1.charAt(tCharNumber)==tString2.charAt(tCharNumber))
{
tCounter++;
}
}
System.out.println(tCounter);
}
}

<a href="http://www.yesadvertising.com">affiliate marketing</a>

Back to Featured Articles on Logo Paperblog

Magazines