Java program to accept a sentence and display the words having length is greater than 5

 Java program to accept a sentence and display the words having length is greater than 5


import java.util.Scanner;

public class demo{

public static void main(String args[]) {

    Scanner sc = new Scanner(System.in);

    System.out.print("Enter the String: ");

    String str = sc.nextLine();

    sc.close();

            for(String temp : str.split(" ")) {

if(temp.length()>5)

    System.out.println(temp);

    }

}

}

Comments