Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication2;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- /**
- *
- * @author itexam
- */
- public class Main {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Scanner in=new Scanner(System.in);
- String input=in.nextLine().toLowerCase();
- String[] inputarray=input.split(" ");
- String[] temparray=new String[inputarray.length];
- List<String> index=new ArrayList();
- List<Integer> newindex=new ArrayList();
- for(int i=0;i<inputarray.length;i++)
- {
- char[] chararray=inputarray[i].toCharArray();
- java.util.Arrays.sort(chararray);
- temparray[i]=String.valueOf(chararray).toString();
- }
- for(int i=0;i<inputarray.length;i++)
- {
- String temp=temparray[i];
- for(int j=i+1;j<inputarray.length;j++)
- {
- if(temp.equals(temparray[j])&&!inputarray[i].equals(inputarray[j]))
- {
- if(index.indexOf(inputarray[i])==-1)
- {
- index.add(inputarray[i]);
- newindex.add(i);
- }
- if(index.indexOf(inputarray[j])==-1)
- {
- index.add(inputarray[j]);
- newindex.add(j);
- }
- }
- }
- }
- int indexx=0;
- for(int j=0;j<index.size();j++)
- {
- if(indexx+1<index.size()&&temparray[newindex.get(indexx)].equals(temparray[newindex.get(indexx+1)]))
- System.out.print(index.get(indexx++)+" ");
- else
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement