OneCompiler

PRINT LARGEST AND SMALLEST WORD IN A SENTENCE

136

import java.util.*;

public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
str=str+" ";
String wod="";
int len=0;
String word []=new String[100];
for(int i=0;i<str.length();i++){
if(str.charAt(i)==' '){
word[len]=wod;
len++;
wod="";
}
else{
wod=wod+str.charAt(i);
}
}
String small,large;
small=large=word[0];
System.out.println(small.length());
for(int i=0;i<len;i++){
if(small.length()>word[i].length()){
small=word[i];
System.out.println("sw"+small);
}
if(large.length()<word[i].length())
large=word[i];
}
System.out.print("small word:"+small+"\nlarge word:"+large);
}
}