English

Design a Class to Overload a Function Joystring( ) as Follows :

Advertisements

Question

Design a class to overload a function Joystring( )as follows:

(i) void Joystring (String s, char ch1 char ch2) with one string argument and two character arguments that replaces the character argument ch1 with the character argument ch2 in the given string s and prints the new string.
Example:
Input value of s = “TECHNALAGY”
ch1=‘A’,
ch2=‘O’
Output: TECHNOLOGY
(ii) void Joystring (String s) with one string argument that prints the position of the first space and the last space of the given string s.
Example:
Input value of = “Cloud computing means Internet based computing”
Output: First index: 5
Last index: 36
(iii) void Joystring (String s1, String s2) with two string arguments that combines the two string with a space between them and prints the resultant string. Example :
Input value of s1 =“COMMON WEALTH”
Input value of s2 =“GAMES”
Output: COMMON WEALTH GAMES
(use library functions)

Answer in Brief
Advertisements

Solution

Class Overload
{
    void Joystring (string s , char ch1 , char ch2);
{
    S = S.replace (ch1 , ch2);
    System.out.println ("New String" +S);
    }
            void joystring (String S)
   {
            int i1 = S.indexOf('');
            int i2 = S.last Indexof('');
           System.out.println ("Position of 1st space" +i1);
           System.out.println ("Position of last space" +i2);

}
           void Joystring (string s1, string s2)

{
           String s3 = s1.concat(" ");
                     s3 = s3.concat (s2);
                     system.out.println ("new string" + s3);
}
}     

shaalaa.com
  Is there an error in this question or solution?
2014-2015 (March) Set 1
Advertisements
Share
Notifications



      Forgot password?
Use app×