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

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
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-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-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-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
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
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
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
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
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
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 (adsbygoogle
A program to find the largest word in String
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
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
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
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
String file in to word file in java
String file in to word file in java  How to convert a String format notepad file into Ms word file in java
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 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
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="
String file in to word file in java
String file in to word file in java  how to convert a String format word file into Ms Word file using java? please can anyone of you help me
convert word document to pdf
convert word document to pdf  Hi, Could you please help me write a java code that converts the word docuemnt into PDF? I have to save the generated PDFs also. I got a code like the below, and i am unable to download the office
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
store form data into word document
store form data into word document  i want form page data, ex username phone number.. to store it in a word document file
click a word and search it from a file
click a word and search it from a file  i want to link a word with a file and search it form the file by clicking it. what could the code for this process
ModuleNotFoundError: No module named 'painted-word'
ModuleNotFoundError: No module named 'painted-word'  Hi, My Python... 'painted-word' How to remove the ModuleNotFoundError: No module named 'painted-word' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Random-Word'
ModuleNotFoundError: No module named 'Random-Word'  Hi, My Python... 'Random-Word' How to remove the ModuleNotFoundError: No module named 'Random-Word' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'rpaframework-word'
ModuleNotFoundError: No module named 'rpaframework-word'  Hi, My... named 'rpaframework-word' How to remove the ModuleNotFoundError: No module named 'rpaframework-word' error? Thanks   Hi, In your

Ads