Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Interview-Questions finout longest word in sentence
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ASHUTOSH PRADHAN
finout longest word in sentence
1 Answer(s)      3 years and 11 months ago
Posted in : Java Interview Questions


write a program , how to find out the longest word in a sentence using java


Advertisement
View Answers

January 25, 2011 at 10:36 AM


Hi Friend,

Try the following code:

import java.util.*;

class LongestWord
{
Scanner input=new Scanner(System.in);
System.out.println("Enter string: ");
String str=input.nextLine();
String stringArray[] = str.split("\\s");
public String compare(String st1, String st2){
if(st1.length()>st2.length()){
return st1;
}
else{
return st2;
}
}
LongestWord(){
String word = "";
for(int i=0;i<stringArray.length;i++){
if(i==0){
word = stringArray[0];
}
word = compare(word, stringArray[i]);
}
System.out.println("Longest word = " + word);
}
public static void main(String []args){
new LongestWord();
}
}

Thanks



Related Tutorials/Questions & Answers:
finout longest word in sentence
finout longest word in sentence  write a program , how to find out the longest word in a sentence using java   Hi Friend, Try...]); } System.out.println("Longest word = " + word); } public static void main(String []args){ new
Write a program in JAVA which accepts a sentence & displays the longest word in the sentence alongn with it length of the word.
Write a program in JAVA which accepts a sentence & displays the longest word in the sentence alongn with it length of the word.  **A program in JAVA which accepts a sentence & displays the longest word in the sentence along
Advertisements
Finding the longest word in a user given string
Finding the longest word in a user given string  In java, accept a string from the user and find the longest word in it.   The given code finds the longest word from the string. import java.util.*; class LongestWord
Find Longest Word from the string using Java
Find Longest Word from the string using Java Here we are going to find the longest word from the string. For this, we have specified the string which... and allow the longest word to display. Here is the code
accept sentence from user and print all word starts with vowel and end with consonent
accept sentence from user and print all word starts with vowel and end with consonent  Write a program to accept a sentence. Print all the words that starts with vowel and end with a consonant. e.g. input by user "the purpose
print word with max vowels
print word with max vowels  if suppose i hava entered a sentence and in that sentence i have to print a word which has maximum vowels in it.... i have tried it but i am not getting it...please help
how to find the sum of integers in a string of sentence in java
how to find the sum of integers in a string of sentence in java  how to find the sum of integers in a string of sentence in java for e.g:--> abc d 2 3 21 the output should be 2+3+21=26
how to write a function to print for finding the longest palindrome in the given string
how to write a function to print for finding the longest palindrome in the given string  how to write a function to print for finding the longest palindrome in the given string
Determining the Sentence Boundaries in a Unicode String
Determining the Sentence Boundaries in a Unicode String In this section, you will learn how to determine the sentence boundaries in a unicode string. From...(). The method getSentenceInstance() create BreakIterator for sentence-breaks using
Question on reversing word of a sentnce
Question on reversing word of a sentnce  Write a function that accepts a sentence as a parameter, and returns the same with each of its words reversed. The returned sentence should have 1 blank space between each pair of words
MicroSoft word
MicroSoft word  sir i want to develop an swing application like the microsoft word Document.can you help me pls
Compare two word file
Compare two word file  How to compare two word file using Java
Write String in Word document
Write String in Word document  How to read and write strings in word document
NUMBER OF VOWELS IN A WORD
NUMBER OF VOWELS IN A WORD  WRITE A PROGRAM THAT WILL INPUT A WORD THEN IT WILL DETERMINE THE NUMBER OF VOWELS PRESENT IN THE INPUTTED WORD
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link.... It will be helpful for you to read data from word document
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link.... It will be helpful for you to read data from word document
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link.... It will be helpful for you to read data from word document
Problem reading word file
Problem reading word file  Deepak you provide me code for extarcting equation from a word file and also to write in a word file.But when I again want to read preveously created word file(created by your code) it gives an error
how to delete a letter in a word?
how to delete a letter in a word?  how to delete a letter in a word? for example if i enter= roseindia, i want to delete 's', then output= roeindia
com in ms word
com in ms word  how to use com object to fetch data from ms word and storing it into sql database
com in ms word
com in ms word  how to use com object to fetch data from ms word and storing it into sql database
Display the data to MS word
the database(say im searching using an id) and should display it on the ms word , i want it to be in a good format. FOr example my word doc has to be Name... a word doc would help a lot!! thank you
Scanning a word in a TEXT document......
Scanning a word in a TEXT document......  Hi Genius persons... I'm having many resumes in my FOLDER called HARISH in D:(colon) i want to scan... by searching the JAVA and .net words present in the files..if JAVA word is present means
Scanning a word in a TEXT document......
Scanning a word in a TEXT document......  Hi Genius persons... I'm having many resumes in my FOLDER called HARISH in D:(colon) i want to scan... by searching the JAVA and .net words present in the files..if JAVA word is present means
Java Word Processor
Java Word Processor  Problem: Design and implement a class called... of words (a hyphenated word is one word), o number of sentences (ends..., exclamation marks, hyphens (within a word), and apostrophes. Words will have only
from number to word
from number to word  i want to know weather there is any method that can be use in changing value from number to word. Example if i write ten thousand, it will automatically be written as 10000.   Java convert number
Word replacment - Java Beginners
Word replacment  Java code for the Word Replacement.Thnaks in Advance!  Hipublic class WordReplaced{ public static void main(String[] args){ String str1="the fat boy and his father"; String strreplace1="
word program - Java Beginners
word program  HELLO MAM AND SIR I ASK YOUR HELP HOPE YOU GONNA HELP ME THANK YOU!!Design a program to search a word for letters that the user... within the word a letter that the user entered,change the value of the array
letter counting for the smallest word
and it works EXCEPT that it counts all of the letters not just the smallest word...(); int count=ch.length; System.out.println("Count of smallest word
 

 

 

DMCA.com