(1) Write a program in Java to accept a string (cointaining three words) and display the new string after reversing each character of the word. Sample Input: India is my country
Output: aidn1 si ym yrtnuot .uestion
(2) Write a program in Java to accept a string and find the frequency of a word entered by the user in the string. However the word should not be a part of a string. Sample Input: Ambani brothers are one of the leading industralist of the country. Frequency of the word to be searched: theSample output:2
(3) Consider the following statement: :"January 26 is celebrated as the Republic Day of India" .WAP in java to change 26 to 15, January to August, Republic to Independence and finally print "August 15 is celebrated as the Independence day of India."
Answers
Answered by
2
1)
class Reverse
{
void main(String s)
{
int n=s.length();
String s1="";
for(int i=n-1; i>=0; i--)
{
s1=s1+s.charAt(i);
}
S.o.p(s1);
}
}
2)
import java.util.*;
class Check
{
void main()
{
Scanner sn=new Scanner(System.in);
S.o.p("Enter a string - ");
String s=sn.nextLine();
S.o.p("Enter the word to be searched - ")
String s1=sn.nextLine();
s=s.toLowerCase();
int n=s.length();
int count = 0;
for(int i=0; i<=n-1; i++)
{
if((s1.charAt(i))equals(s.charAt(j)))
{
count++;
}
}
S.o.p("frequency - "+ count);
}
}
class Reverse
{
void main(String s)
{
int n=s.length();
String s1="";
for(int i=n-1; i>=0; i--)
{
s1=s1+s.charAt(i);
}
S.o.p(s1);
}
}
2)
import java.util.*;
class Check
{
void main()
{
Scanner sn=new Scanner(System.in);
S.o.p("Enter a string - ");
String s=sn.nextLine();
S.o.p("Enter the word to be searched - ")
String s1=sn.nextLine();
s=s.toLowerCase();
int n=s.length();
int count = 0;
for(int i=0; i<=n-1; i++)
{
if((s1.charAt(i))equals(s.charAt(j)))
{
count++;
}
}
S.o.p("frequency - "+ count);
}
}
prakriti27:
pls!!! mark as the best........
Similar questions