Q-WAP TO OVERLOAD A STRING AND BOOLEAN FUNCTION “check” TO PERFORM THE FOLLOWING TASK-: A-REVERSE A STRING. B-SEARCH A CHARACTER IN STRING.

import java.util.*;
class overload
{
public String check(String str)
{
String t="";
for(int i=0;i<str.length();i++)
{
char ch=str.charAt(i);
t=ch+t
}
return t;
}
public boolean check(String str,char ch)
{
int k=0;
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)==ch)
{
k=1;
break;
}
else
k=0;
}
if(k==1)
return true;
else
return false;
}
public static void main(String args[])
{
String str="";char ch;String r="";boolean t;
Scanner ob=new Scanner(System.in);
overload obj=new overload();
System.out.println("ENTER STR");
str=ob.nextLine();
System.out.println("ENTER CHARACTER");
ch=ob.next().charAt(0);
r=obj.check(str);
System.out.println(r);
t=obj.check(str,ch);
if(t==true)
System.out.println("PRESENT");
else
System.out.println("NOT PRESENT");
}
}




Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s