Thứ Ba, 26 tháng 8, 2014

Second version of finding common letters in "AMITABH BHACHAN" and "RAJINIKANTH"

Hi Guys,,

you know why am focusing on this java program especially??????

-->the reason is if you ever applied an internship through twenty20.com  ,every company asking code for this program[I don't know why they are giving same program for all recruitment ].

In my previous version am developed a solution using stringbuffer classes it becomes very lengthy and bit of confusing,so here am giving a simple solution .follow this



solution:
==============
package logics;
import java.util.*;
public class amitabhRajini {
    public static void main(String[] args)
    {
        String name1="AMITABH BHACHAN";
        String name2="RAJINIKANTH";
        char []array1=name1.toCharArray();
        char []array2=name2.toCharArray();
        Set<Character> s=new HashSet<Character>();
        Set<Character> common=new HashSet<Character>();
        for(char che:array1)
        {
            s.add(che);
          
        }
        for(char che1:array2)
        {
            if(s.contains(che1))
            {
                common.add(che1);
            }
        }
        System.out.print(common);
      
      
    }
}


output :

---------------------------------
[T, A, N, H, I]

Không có nhận xét nào:

Đăng nhận xét