English

Observe the following code. It may contain Syntax, Logical or runtime errors. int fnConsign(int a, int b) { if(a > b) { return а; } if(b > a) { return b;} }

Advertisements
Advertisements

Question

Observe the following code. It may contain Syntax, Logical or runtime errors. Execute it in Java and identify the error, if any. Rewrite the code without the error. Also write the aim of the code.

int fnConsign(int a, int b)
{
    if(a > b)
    {
        return а;
    }
    if(b > a)
    {
        return b;
    }
}
Code Writing
Advertisements

Solution

int fnConsign(int a, int b)
{
    int max;
    if (a > b)
    {
        max = a;
    }
    else
    {
        max = b;
    }
    return max;
}
shaalaa.com
  Is there an error in this question or solution?
Chapter 3: User-Defined Methods - Exercises [Page 93]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 3 User-Defined Methods
Exercises | Q 7. (viii) | Page 93
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×