public class Main { public static void main(String[] args) { String words = "One Two Three Four"; int countWords = words.split("\\s").length; System.out.println(countWords); } } // Outputs 4
Reverse a String
public class Main { public static void main(String[] args) { String originalStr = "Hello"; String reversedStr = ""; System.out.println("Original string: " + originalStr); for (int i = 0; i < originalStr.length(); i++) { reversedStr = originalStr.charAt(i) + reversedStr; } System.out.println("Reversed string: "+ reversedStr); } }
标签:Count,Java,String,originalStr,System,How,reversedStr,public,out From: https://www.cnblogs.com/ShengLiu/p/16931061.html