finout longest word in sentence

Ads
 

finout longest word in sentence

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

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

Ads









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
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
ModuleNotFoundError: No module named 'sentence-diff'
ModuleNotFoundError: No module named 'sentence-diff'  Hi, My... 'sentence-diff' How to remove the ModuleNotFoundError: No module named 'sentence-diff' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'sentence-splitter'
ModuleNotFoundError: No module named 'sentence-splitter'  Hi, My... named 'sentence-splitter' How to remove the ModuleNotFoundError: No module named 'sentence-splitter' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'sentence-url'
ModuleNotFoundError: No module named 'sentence-url'  Hi, My Python... 'sentence-url' How to remove the ModuleNotFoundError: No module named 'sentence-url' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'text-sentence'
ModuleNotFoundError: No module named 'text-sentence'  Hi, My... 'text-sentence' How to remove the ModuleNotFoundError: No module named 'text-sentence' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'sentence-segmenter'
ModuleNotFoundError: No module named 'sentence-segmenter'  Hi, My... named 'sentence-segmenter' How to remove the ModuleNotFoundError: No module named 'sentence-segmenter' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'sentence-transformers'
ModuleNotFoundError: No module named 'sentence-transformers'  Hi...: No module named 'sentence-transformers' How to remove the ModuleNotFoundError: No module named 'sentence-transformers' error? Thanks   Hi
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
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
A program to find the largest word in String
ModuleNotFoundError: No module named 'CTH-sentence-split'
ModuleNotFoundError: No module named 'CTH-sentence-split'  Hi, My... named 'CTH-sentence-split' How to remove the ModuleNotFoundError: No module named 'CTH-sentence-split' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'ja-sentence-segmenter'
ModuleNotFoundError: No module named 'ja-sentence-segmenter'  Hi...: No module named 'ja-sentence-segmenter' How to remove the ModuleNotFoundError: No module named 'ja-sentence-segmenter' error? Thanks   Hi
ModuleNotFoundError: No module named 'ja-sentence-segmenter'
ModuleNotFoundError: No module named 'ja-sentence-segmenter'  Hi...: No module named 'ja-sentence-segmenter' How to remove the ModuleNotFoundError: No module named 'ja-sentence-segmenter' error? Thanks   Hi
ModuleNotFoundError: No module named 'ja-sentence-segmenter'
ModuleNotFoundError: No module named 'ja-sentence-segmenter'  Hi...: No module named 'ja-sentence-segmenter' How to remove the ModuleNotFoundError: No module named 'ja-sentence-segmenter' error? Thanks   Hi
ModuleNotFoundError: No module named 'pinyin_jyutping_sentence'
ModuleNotFoundError: No module named 'pinyin_jyutping_sentence'  Hi...: No module named 'pinyin_jyutping_sentence' How to remove the ModuleNotFoundError: No module named 'pinyin_jyutping_sentence' error? Thanks  
ModuleNotFoundError: No module named 'sentence-sem-sim'
ModuleNotFoundError: No module named 'sentence-sem-sim'  Hi, My... named 'sentence-sem-sim' How to remove the ModuleNotFoundError: No module named 'sentence-sem-sim' error? Thanks   Hi, In your
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
MicroSoft word
MicroSoft word  sir i want to develop an swing application like the microsoft word Document.can you help me pls
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
Write String in Word document
Write String in Word document  How to read and write strings in word document
Compare two word file
Compare two word file  How to compare two word file using Java
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
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
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

Ads