so I have this task where I must enter two strings and after that I have to find what are there common letters,and then write them out but only once..so for example if the string1 is "onomatopoeia" and string2 is "conversation" I should get back: o,n,a,t,e,i... My only problem is the last part("I don't know how to write the letters only once)
here is my code
import java.util.Scanner;
import java.util.Arrays;
public class Zadatak4 {
/**
* @param args
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
char niz[] = new char[100];
char niz2[] = new char[100];
System.out.print("Add the first string: ");
niz = scan.nextLine().toCharArray();
System.out.print("Add the second string: ");
niz2 = scan.nextLine().toCharArray();
for (int i = 0; i < niz.length; i++) {
for (int j = 0; j < niz2.length; j++) {
if (niz[i] == niz2[j]) {
System.out.println(niz[i] + " ");
// What now!?!?!?
}
}
}
}
}