KnowledgeBoat Logo

Output Questions for Class 10 ICSE Computer Applications

Give output of the following method definition and also write the mathematical operation they carry out:


void test4(String x, String y)
{
    if(x.compareTo(y) > 0)
        System.out.println(x);
    else
        System.out.println(y);
}

if "AMIT" and "AMAN" are passed to the method.

Java

User Defined Methods

135 Likes

Answer

AMIT

Working

The first differing characters of "AMIT" and "AMAN" are 'I' and 'A', respectively. So output of "AMIT".compareTo("AMAN") will be ASCII Code of 'I' - ASCII Code of 'A' ⇒ 73 - 65 ⇒ 8. The if condition is true so string x which is "AMIT" gets printed as the output.

Answered By

71 Likes