Computer Science, asked by niteshmlgandhi, 8 months ago

plz slove this program it's very very urgent any one plz and no spam plz​

Attachments:

Answers

Answered by XxRonakxX
18

write your questions properly ok

Answered by PRahul
1

Answer:

import java.util.Scanner;

public class Prahul {

   public static void main(String[] args)

   {

       Scanner sc = new Scanner(System.in);

       int i,longleng=0,smal_leng=4, l , three_letter_word=0;

//longleng stores length of longest word

//smalleng stores length of shortest word

// l store the length of particular word

//three_letter_word stores the no of 3 letter word

       String s,w="",lw="",sw="";  

//lw stores longest word and sw stores smallest word

       char c;

       System.out.println("enter a sentence");

       s=sc.nextLine().trim();

       s=s+" ";

       for(i=0;i<s.length();i++){

           c=s.charAt(i);

           if(c!= ' '){

               w=w+c;

           }

           else{

               l=w.length();

               if(l==3){

                   three_letter_word++ ;

                     }

               if(l>longleng){

                   longleng=l;

                   lw=w;

                    }

               else if(l<=smal_leng) {

                  smal_leng = l;

                   sw = w;

                  }

               w="";

           }

       }

       System.out.println("longest word= "+ lw + " no of characters = " +longleng);

       System.out.println("shortest word= "+sw+ " no of characters = " +smal_leng);

       System.out.println("no of three letter word word= "+ three_letter_word);

   }

}

Similar questions