Computer Science, asked by sagarikaash1, 6 months ago

Design a class to overload the function display(......) as follows:
(1) void display(String str, char ch): checks whether the word str contains the letter
ch at the beginning as well as at the end or not. If present, print 'Special Word'
otherwise print 'No special word'.
(ii) void display(String str1, String str2): checks and prints whether both the words are
equal or not
(iii)void display(String str, int n): prints the character present at nth position in the
word str.
Write a suitable main() function

RIGHT ANSWER NEEDE OR YOU WILL BE REPORTED.....​

Answers

Answered by anindyaadhikari13
11

class Overloading

{

void display(String str, char ch)

{

char x=str.charAt(0);

char y=str.charAt(str.length()-1);

if(x==y && x==ch)

System.out.println("Special Word. ");

else

System.out.println("Not a Special Word.");

}

void display(String str1, String str2)

{

if(str1.equalsIgnoreCase(str2))

System.out.println("Both the strings are equal.");

else

System.out.println("Both the strings are not equal.");

}

void display(String str, int n)

{

if(n<str.length())

System.out.print(str.charAt(n));

else

System.out.println("Index out of bounds. ");

}

public static void main(String args[])

{

Overloading obj=new Overloading();

obj.display("ma'am",'m');

obj.display("Welcome", "Welcome");

obj.display("Welcome.",0);

}

}

Similar questions