Computer Science, asked by jojo2020draidi, 3 months ago

Write a Java method that receives three strings and returns a string containing distinct common characters among the three strings ignoring case for letters.
Write a program to test this method.​

Answers

Answered by dreamrob
1

Program:

import java.util.*;

public class MyClass

{

   public static String distinct (String s1, String s2, String s3)

   {

       String all = s1 + s2 + s3;

       all = all.toUpperCase();

       String res = "";

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

       {

           if (!res.contains(String.valueOf(all.charAt(i))))

           {

               res = res + String.valueOf(all.charAt(i));

           }

       }

       return res;

   }

   public static void main(String args[])

   {

       Scanner Sc = new Scanner(System.in);

       System.out.print("Enter String 1 : ");

       String s1 = Sc.next();

       System.out.print("Enter String 2 : ");

       String s2 = Sc.next();

       System.out.print("Enter String 3 : ");

       String s3 = Sc.next();

       String res = distinct(s1, s2, s3);

       System.out.println(res);

   }

}

Output:

Enter String 1 : Nirali

Enter String 2 : Poorvi

Enter String 3 : Rajiv

NIRALPOVJ

Similar questions