100% found this document useful (2 votes)
3K views2 pages

WIPRO LOGIC BUILDING JAVA PROGRAMS Most Important (PART-II)

The document discusses a Java method to find a password by taking in 5 integer inputs, determining if each input number is stable or unstable based on the frequency of its digits, summing the stable numbers and unstable numbers, and returning the difference between the two sums. The method uses arrays, lists, and maps to separate the numbers into stable and unstable categories before calculating the final password value.

Uploaded by

kummetha vanitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
3K views2 pages

WIPRO LOGIC BUILDING JAVA PROGRAMS Most Important (PART-II)

The document discusses a Java method to find a password by taking in 5 integer inputs, determining if each input number is stable or unstable based on the frequency of its digits, summing the stable numbers and unstable numbers, and returning the difference between the two sums. The method uses arrays, lists, and maps to separate the numbers into stable and unstable categories before calculating the final password value.

Uploaded by

kummetha vanitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

SRI SAIRAM

WIPRO LOGIC BUILDING PROBLEMS JAVA SOLUTIONS (PART-2)

Find Password (Stable and Unstable) https://tests.mettl.com/authenticateKey/5106dfd

import java.util.*;
import java.io.*;
class UserMainCode{
public int findPassword(int input1,int input2,int input3,int input4,int input5){
input1=Math.abs(input1);
        input2=Math.abs(input2);
        input3=Math.abs(input3);
        input4=Math.abs(input4);
        input5=Math.abs(input5);
        int a[]={input1,input2,input3,input4,input5};
        int num;
        ArrayList<Integer> al=new ArrayList<Integer>();
        ArrayList<Integer> sn=new ArrayList<Integer>();
        ArrayList<Integer> usn=new ArrayList<Integer>();
        for(int i=0;i<5;i++){
            num=a[i];
            int x=0;
            while(num>0){
                al.add(num%10);
                num=num/10;
                x++;
            }
            Map<Integer,Integer> hm=new HashMap<Integer,Integer>();
            for(int j=0;j<al.size();j++){
                int ele=al.get(j);
                if(hm.containsKey(ele)){
                    int k=hm.get(ele);
                    hm.put(ele,++k);
                }
                else
                 hm.put(ele,1);
            }
            al.clear();
            Collection<Integer> vls=hm.values();
            Object cl[]=vls.toArray();
            int flag=1;
            int ele=(Integer)cl[0];
            for(Object y:cl){
                if((Integer)y==ele)
                    continue;
                else{
                 flag=0;
                    break;
                }
            }
            if(flag==0)
                usn.add(a[i]);
            else
             sn.add(a[i]);
        }
int sumsn=0,sumusn=0;
        for(int e:sn)
            sumsn=sumsn+e;
        for(int e:usn)
            sumusn=sumusn+e;
        return (sumsn-sumusn);
}
}

You might also like