Computer Science, asked by lepcharenzongcalvin, 7 months ago

write a program in java to enter a string and print the smallest word present and also print the total characters present in the smallest word using scanner class nd for loop ​

Answers

Answered by hoangmustang
1

Answer:

check out my solution!

package newPack;

import java.util.*;

public class smallestWord {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

String s = input.nextLine();

String [] a = s.split(" ");//split the string into string array

long smallest = 1000000000000l;

String j = " ";

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

 if(a[i].length()<smallest) {

  smallest = a[i].length();//find the smaller length end of loop, we will get smallest

  j = a[i];

 }

}

System.out.println(j + " " +smallest);

}

}

Explanation:

Similar questions