Examveda
Examveda

What will be the output of the following Java code?
class output 
{
    public static void main(String args[])
    {
         String chars[] = {"a", "b", "c", "a", "c"};
         for (int i = 0; i < chars.length; ++i)
             for (int j = i + 1; j < chars.length; ++j)
                 if(chars[i].compareTo(chars[j]) == 0)
                     System.out.print(chars[j]); 
    }
}

A. ab

B. bc

C. ca

D. ac

Answer: Option D


This Question Belongs to Java Program >> Strings

Join The Discussion

Related Questions on Strings