'String substring(int start)' returns the sub-string from 'start' to end of the string, 'int indexOf()' function returns '-1' when the argument value is not present in the invoking string object. They can then check out your code, or even use your program with BlueJ as the visual interface Method 1 - Email. Next another overloaded version of 'substring' function is called. Word 'word' using 'boolean equalsIgnoreCase(String s)' function. That means the left most words from the sentence will be retrieved which is compared with the Here in this program, we have passed '0' and 'pos' as arguments. 'String substring(int start, int end)' is another String class function which returns the sub-string of the invoking string object starting from the location specified by 'start' and upto the location 'end'. This function has several overloaded versions. 'int indexOf(char ch)' is a function of String class which returns the first occurrence location of the character 'ch' in the invoking string object. Within this function body an 'int' type variable pos is declared and used to store the location of blank space in the sentence. Within this function body the main job is performed and number of String class functions is used.Īn infinite while loop is used to retrieve the words from the sentence. This function eliminates the leading and trailing spaces of a string, if any and returns a modified string object. In both the cases input values are trimmed using the String class function 'String trim()'. This function will take the sentence and the word to be searched from the user. For Java programming, it adds tabbed editors, automatic error-checking, adds display of multiple errors and has most of the BlueJ interface rewritten into JavaFX (solving many HiDPI issues on Windows) while also providing some support for writing JavaFX applications and including JavaFX CSS files in a project. One 'int' type variable 'count' is used in this program to count the occurrences of the word 'word' in the sentence 'str'.īufferedReader class object 'br' is used for console input.įunctions used in this program and details about the program
The fourth String object 'word' will hold the word to be searched from the sentence. String str1 will hold the console input sentence and the values will be assigned on another String object 'str'.The third String object 'substr' will be used to store the words of the sentence stored in 'str1'. Public static void main(String args) throws Exceptionįour String class objects are declared in this program. ("The word " + word + " is present for " + count + " times in the sentence " + str)
#Bluej program download
Public void takeString() throws Exception BlueJ for Windows 5.0.2 Download BlueJ for all platforms 1/4 BlueJ is perfect for students that are beginners in the Java environment and it is a perfect introduction. BufferedReader br=new BufferedReader(new InputStreamReader(System.in))