answersLogoWhite

0

class LongestWord

{

String str = "Ram is intelligent boy";

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

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();

}

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

Write a program in java to display a string message using Servlets?

i dont no string for servlate


Write a java program to count the space from the given line?

.... String line = "This is example program with spaces"; String[] tokens = line.split(" "); System.out.println(tokens.length-1); .......


Write a program to change the case of the given string?

This functionality is already in Java. String.toLowerCase() and String.toUpperCase() will take care of it for you.


Write a java program to initialize array of string with the days of the week?

final String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};


How to write A Java program to print number of digits in a given number?

One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.


How do you write a program using function that counts the number of vowels in a string in java language?

Use text-editor notepad++


Write a java program to pass a string have a good day from command line?

public class HaveAGoodDay { public static void main(String[] args) { for (final String arg : args){ System.out.print(arg +" "); } } } compile and run the program: java HaveAGoodDay have a good day. output: have a good day.


Write a Java Program to find occurences of given word in a text?

Check the documentation of the String class, for a method that searches for a substring.


Can we add website link when we write java program?

yes ,i can add the website link in java program when we write.


How to Write a java program to display hello?

public class Hello{public static void main(String [] args){System.out.println("Hello");}}


How can you write an interface name M and In the interface M place 2 methods named taste and smell both return String type in java program?

interface M { String taste(); String smell(); }


How does the string trim work in Java?

The string trim works in Java by trimming white space from the beginning and end of a string. It cleans up the string and makes makes it neater for the users of the program.