WAP to accept a string and find the frequency of the word present in the string.

SAMPLE INPUT : Tata Steel is one of the Steel manufacturing company of the country; 

Frequency of the word to be searched : the 
OUTPUT : 2 

Program: 
import java.io.*; 
public class string2 

public static void main(String args[])throws IOException 

InputStreamReader read = new InputStreamReader(System.in); 
BufferedReader in = new BufferedReader(read); 

String word=""; 
int sp=0; 
int c=0; 

System.out.println("Enter your String"); 
String sentence = in.readLine(); 
sentence=sentence+" "; 
int len=sentence.length(); 
System.out.println("Enter the word whose frequency is to be found"); 
String search = in.readLine(); 

for(int i=0;i { 
char ch=sentence.charAt(i); 
if (ch==' ') 

word = sentence.substring(sp,i); 
sp=i+1; 

if(word.equalsIgnoreCase(search)==true) 

c++; 




System.out.println("The number of substring "+search+" in the string is "+c); 




Program Execution 

Enter your String 
Einstein was called the best scientist the Germans and the world has witnessed. 
Enter the word whose frequency is to be found 
theThe number of substring the in the string is 3 

WAP in Java to accept a word and display the same word in Pig Latin form.

Sample Input: trouble
Output: oubletray

Program :
import java.io.*;
public class string1
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);

System.out.println("Enter the word");

String x=in.readLine();
String word = "";
String word2 = "";
String frame = "";
int sp=0;
int len = x.length();
int p=len+1;

for(int i=0;i {
char ch=x.charAt(i);
if((ch=='a')(ch=='e')(ch=='i')(ch=='o')(ch=='u')(ch=='A')(ch=='E')(ch=='I')(ch=='O')(ch=='U'))
{
word=x.substring(sp,i);
word2=x.substring(i,len);
}
frame=word2+word+"ay";
}
System.out.println(frame);
}
}

Program Execution

Enter the word
Sangam
The word in PigLatin is = amSangay

Java 6 Programming Black Book [eBook] - Rs. 404

Java 6 Programming Black Book Java 6 Programming Black Book 

List Price: Rs.599
Our Price: Rs.404   Buy Now

Book Overview

Java 6 Programming Black Book, New Edition is a onetime reference and a solid introduction, written from the programmer's point of view that contains hundreds of examples covering every aspect of Java 6. It helps you master the entire spectrum of Java 6 from Generics to Security enhancements from new applet deployment enhancements to Networking from Servlets to XML from Sound and Animation to database handling from Java Naming from Internationalization to Dynamic Scripting and Groovy and much more.

Book Details

Language English
Publisher Wiley India
ISBN 9789350046524
Publication Date 2007-01-01
File Size 50.61 MB

Bluej program to check Pythagorean triplet

Write a program to input 3 nos. and check whether they are Pythogorean Triplet . or not .The program must display the message accordingly.

some Pythagorean triplets are
( 3, 4, 5)
( 5, 12, 13)
( 7, 24, 25)
( 8, 15, 17)
( 9, 40, 41)
(11, 60, 61)
(12, 35, 37)
(13, 84, 85)
(16, 63, 65)
(20, 21, 29)
(28, 45, 53)
(33, 56, 65)
(36, 77, 85)
(39, 80, 89)
(48, 55, 73)
(65, 72, 97)


BlueJ Code:

-------------------------------------------------------------------------------------

import java.io.*;
class pytha
{
void main()throws IOException
{
BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
int a,b,c;
System.out.println("enter no.");
a=Integer.parseInt(obj.readLine());
System.out.println("enter no.");
b=Integer.parseInt(obj.readLine());
System.out.println("enter no.");
c=Integer.parseInt(obj.readLine());
if (a*a==b*b+c*c)
System.out.println("They are Pythogorean Triplet");
else if(b*b==a*a+c*c)
System.out.println("They are Pythogorean Triplet ");
else if(c*c==a*a+b*b)
System.out.println("They are Pythogorean Triplet a² + b² = c² ");
else
System.out.println("Test Failed !!! They are Non Pythogorean Triplet ");
}
}
Note:Remove first 2 conditions, 
if want to consider a² + b² = c² only

Get your own site just for Rs.99. No Tech Knowledge Required. 

All Rights Reserved