dimanche 1 mars 2015

Getting differences in two strings using scanner

I am trying to create a program in Java that allows the user to enter two words and the system prints out the difference in those words. For example, If I entered "frog", and "dog", it would print out "d f r". This is what I have so far:



public static void main(String[] args) {

Scanner myScan = new Scanner(System.in);
System.out.println("Enter first word:");
String st1 = myScan.nextLine();
Scanner myScan2 = new Scanner(System.in);
System.out.println("Enter second word:");
String st2 = myScan2.nextLine();
strDiff(st1, st2);



}

public static void strDiff(String str1, String str2){
String[] hr = str2.split("\n");
for (String h : hr) {
if (!str1.contains(h)) {
System.out.println("The differences are: " + h);
}

Aucun commentaire:

Enregistrer un commentaire