Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Collection {
- String[] strings;
- private static Collection ourInstance = new Collection();
- public static Collection getInstance() {
- return ourInstance;
- }
- private Collection() {
- }
- public void readConsole(){
- System.out.println("Enter String:");
- Scanner scanner = new Scanner(System.in);
- String s = scanner.nextLine();
- strings = s.split("\\s");
- }
- public String sameLetters(){
- try {
- String lettersOutput = new String();
- for (int i = 0; i < strings[0].length(); i++) {
- char c = strings[0].charAt(i);
- if (strings[1].indexOf(c) != -1 && strings[2].indexOf(c) != -1 && lettersOutput.indexOf(c) == -1)
- lettersOutput += strings[0].charAt(i);
- }
- return lettersOutput;
- }
- catch (IndexOutOfBoundsException e){
- return "There are not enough strings to find similar letters";
- }
- }
- public String[] getStrings(){
- return strings;
- }
- @Override
- public String toString(){
- String result = new String();
- for (int i = 0; i < strings.length; i++){
- result += strings[i] + "\n";
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement