Ad Code

Responsive Advertisement

how to find largest word in a string.

How to find Largest Word in a String.

Here we are going to find the Largest Word In a String. The Largest Word are find into a String in java.


Steps  To how to find Largest Word in a String.


  1. First we create a char array[] To store entire words of a String.
  2. Second we create a String Buffer to Store all the words of a string
  3. Then we use the for loop to start from [0] index to ['\0'] NULL index of a String.
  4. and we used a if condition to divide all the word of a string.
  5. and we use an integer veriable to store the first length word of a String
  6. And then we compare all the length of a String word to te length(Integer) veriable And which length is largest then the other String word this is called Largest Word of a String.


The Output Of programTo find Largest Word in a String



Input : "This is a test string"
Output : Maximum length word: string

Input : "codewithvibhu A computer Science portal" 
Output : Maximum length word: codewithvibhu



how to find Largest Word in a String













#import java.util.*;
class try1{
  public static void main(String[] args) {     
    StringBuffer name[]=new StringBuffer[8];    /* Here we Using a String Buffer To Store all the words*/
    char a;
    char[] b=new char[18];              //It is a character Array to Store entire String
    Scanner input=new Scanner(System.in);
    System.out.print("Enter a String :");
    b=input.nextLine().toCharArray(); 
    int j=0,k=0;         
    for(int i=0; i<4; i++){
      name[i]=new StringBuffer();        /* Create all the String Buffer */
    }
    for(int i=0; i<b.length; i++){
      if(b[i] ==' '){
        j++;                /* Check if the word is Equal to Space  */
        k=0;
      }else{
        name[j].append(b[i]);
        k++;              // If the Word is not Space then
      }                  // It Store into the String Buffer
    }
    int len=name[0].length();        /* Assign the First Word Length */
    for(int i=0; i<=j; i++){
      if(len<=name[i].length()){
        len=name[i].length();      // Check if the len is greater then the other
      }                  // then it Assign into the len
    } 
    for(int i=0; i<=j; i++){
      if(len<=name[i].length()){
        System.out.println("Highest Length is :"+name[i]);
      }
    }
  }
}



out put :
 

Enter a String :my name is vibhu
Highest length is vibhu

How to find Largest Word in a String in C .

Download the programs file:

👉 Click Here To Download the File ðŸ‘ˆ


If you like code with vibhu  and would like to contribute, you can also write an article using   This link :

https://docs.google.com/forms/d/e/1FAIpQLScAmvlPvNUz35R-G0nc_zpRVP3o8xlhtFgC3aKPyLetX_RyXg/viewform?pli=1


OR  mail your article to codewithvibhu@gmail.com.  See your article appearing on the code with vibhu main page and help other students. 

And also Like and comment our program👇.

Post a Comment

2 Comments

  1. https://drive.google.com/file/d/1yW1XxFQBHMcnB2TKnk89axy_1QAv-duF/view?usp=sharing

    ReplyDelete
  2. https://drive.google.com/file/d/1GvtxwpBfe0ALceiJ9WEESOGURtwPK0Ru/view?usp=drivesdk new vb

    ReplyDelete