English

Write a program as per the given specification. Design a class to overload a method Action () given that (a) void Action (int, int) - Print the larger variable

Advertisements
Advertisements

Question

Write a program as per the given specification.

Design a class to overload a method Action () given that

  1. void Action (int, int) - Print the larger variable
  2. void Action (char, char) - Print the first character in lower case, second character in upper case [assume both are alphabets]
  3. void Action (String, String) – Print the longer string

Write the above methods and the main () method to call the three overloaded methods.

Code Writing
Advertisements

Solution

 import java.util.*;
class clOver
{
   void Action(int a, int b)
   {
      if(a > b)
      {
          System.out.println("Larger is :" + a);
      }
      else if(b > а)
      {
          System.out.println("Greater is :" + b);
      }
      else
      {
          System.out.println("Numbers are Equal
      }
}
void Action(char p, char q)
{
      boolean valid = false;
      if (p>='A' && p <= 'Z'(
      {
          p = Character.toLowerCase(p);
          valid = true;
      }
      if (q >= 'a' && q <= 'z')
          q = Character.toUpperCase(q);
          valid = true;
      }
      if(valid = false)
      {
          System.out.println("Not Valid ");
      }
      else
      {
          System.out.println(p +""+ q);
      }
}
void Action (String s1, String s2)
{
      if(s1.length() > s2.length())
      {
          System.out.println("Longer String is : "+ s1);
      }
      else if(s2.length() > s1.length())
      {
          System.out.println("Bigger String is: "+ s2);
      }
      else
      {
          System.out.println("Strings have equal length. ")
      }
}
void main()
{
      clOver vob = new clOver();
      vob.Action(25, 45);
      vob.Action('A', 'v');
      vob.Action('?', '$');
      vob.Action("Hydrogen", "Oxygen");
   }
}

Output:

Greater is 45

a V

Not Valid

Longer String is Hydrogen

shaalaa.com
  Is there an error in this question or solution?
Chapter 3: User-Defined Methods - Exercises [Page 94]

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×