Search

Q13.Compare two similar Strings in Java

 package practice1;


import java.util.ArrayList;

import java.util.List;


public class CompareTwoSimilarStrings {

static int max1=0;

public static void main(String[] args) {    

        String string1 = "inc Demart";   

        String string2= "Demart inc";

        int count;    

            

        //Converts given string into character array    

        char strng1[] = string1.toCharArray();    

        char strng2[] = string2.toCharArray(); 

        

        System.out.println(string2.length());

            

        System.out.println("Duplicate characters in a given string: ");    

        //Counts each character present in the string    

        for(int i = 0; i <strng1.length; i++) {    

            count = 1;    

            

            

         //   System.out.println("I value is : "+i);

            for(int j = 0; j <strng2.length; j++) {    

           

            //System.out.println("strng1[i]::"+strng1[i]);

            //System.out.println("strng2[j]::"+strng2[j]);

         //    System.out.println("J value is : "+j);

                if(strng1[i] == strng2[j] && strng1[i] != ' ' && strng2[j] != ' ') {    

                    count++;    

                    

                                        

                   

                    //Set string[j] to 0 to avoid printing visited character    

                   strng2[j] = '0';    

                }    

            }    

            //A character is considered as duplicate if count is greater than 1    

            if(count > 1 && strng1[i] != '0' && strng1[i] != ' ' )  { 

           

            int max=0;

           

            max++;

           

            max1=max1+max;

           

            System.out.println("max1 value is::: "+max1);

           

            max++;

                

           

                System.out.println(strng1[i]+" duplicate count is::: "+count); 

              

                

           

            }

                

           

           

            

        }

        

        int m1=max1;

        int m2=strng2.length;

        int m3=(m1*100)/m2;

        System.out.println(m1+"m info"+m2);

        System.out.println(m1+"max percwntage"+m3);

       

        if(m3>50) {

       

        System.out.println("Pass");

        } else {

        System.out.println("fail");

        }

    } 


}



No comments:

Post a Comment