Search the web
Custom Search


Price: Rs.225 Buy from Flipkart.com

Java Language is a new approach for the school students. The matter has been explained in simple language. Programs are user friendly.Each chapter contains a number of solved examples, a set of objectives and short questions followed by long questions.

Author - Vijay Kumar Pandey
---------------------------------------------------------------------------------------------
List Price: Rs.300 Price: Rs.288 Buy from Flipkart.com

This book is for beginning programmers studying the java language. The book teaches object oriented principles, using the BlueJ development environment.
------------------------------------------------------------------------------------------------------------------------------------------------------------
Price: Rs.280 Buy from Flipkart.com

Author - Vijay Kumar Pandey & Dilip Kumar Dey
------------------------------------------------------------------------------------------------------------------------------------------------------------

Flipkart Deal of the Day




Programs Based On Strings

WAP to accept a word and find the longest word in the sentence.

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

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

String sentence = in.readLine();
sentence=sentence+" ";
int len=sentence.length();
int len1=0; int len2=0; int large=0; int sp=0;
String word="";
String word1="";
String word2="";
for(int j=0;j {
char c=sentence.charAt(j);
if(c==' ')
{
word=sentence.substring(sp,j);
len1=word.length();
word2=word;
break;
}
}

for(int i=0;i {
char ch=sentence.charAt(i);
if(ch==' ')
{
word1=sentence.substring(sp,i);
len2=word1.length();
sp=i+1;

if(len2>len1)
{
large=len2;
word2=word1;
}
}
}

int ans=Math.max(large,len1);
System.out.println();
System.out.println("The longest word is = "+word2);
System.out.println("The longest word has "+ans+" alphabets");
}
}


Program Execution

Enter the Sentence
Albert Einstein is the greatest scientist of the world.

The longest word is = scientist
The longest word has 9 alphabets

Post a Comment


Search the web
Custom Search


All Rights Reserved