Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
691 B
1
Indexable
package midterm2;
import java.util.*;
public class midterm1task2 { //its actually task 3

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		System.out.println("Please enter some words: ");
		String words = scan.nextLine();
		String []array = words.split(" ");
		int a = array.length;
		int [] array1 = new int[a];
		
		String b = "";
		for(int i = 0; i<a; i++) {
			array1[i] = array[i].length(); 
		}
		int minimum = array1[0];
		for(int i = 0; i<a; i++) {
			if(array1[i]<minimum) {
				minimum = array1[i];
				b = array[i];
			}
		}
		System.out.println("Smallest word is: " + b);
	}

}