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(); } }
i dont no string for servlate
.... String line = "This is example program with spaces"; String[] tokens = line.split(" "); System.out.println(tokens.length-1); .......
This functionality is already in Java. String.toLowerCase() and String.toUpperCase() will take care of it for you.
final String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
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.
i dont no string for servlate
.... String line = "This is example program with spaces"; String[] tokens = line.split(" "); System.out.println(tokens.length-1); .......
This functionality is already in Java. String.toLowerCase() and String.toUpperCase() will take care of it for you.
final String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
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.
Use text-editor notepad++
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.
Check the documentation of the String class, for a method that searches for a substring.
yes ,i can add the website link in java program when we write.
public class Hello{public static void main(String [] args){System.out.println("Hello");}}
interface M { String taste(); String smell(); }
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.