main.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
// Java program to find all string // which are greater than given length k import java.io.*; import java.util.*; public class GFG { // function find string greater than // length k static void string_k(String s, int k) { // create the empty string String w = ""; // iterate the loop till every space for(int i = 0; i < s.length(); i++) { if(s.charAt(i) != ' ') // append this sub string in // string w w = w + s.charAt(i); else { // if length of current sub // string w is greater than // k then print if(w.length() > k) System.out.print(w + " "); w = ""; } } } // Driver code public static void main(String args[]) { String s = "geek for geeks"; int k = 3; s = s + " "; string_k(s, k); } } // This code is contributed by // Manish Shaw (manishshaw1) |