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