// Nested Loop Example import java.util.Arrays; public class NestedLoop { public static void main(String[] args) { String sArray[] = { "203(*&kjhsa3!", "(&*akhjsdk9812", "slkdj(*&(" }; System.out.println("Array: " + Arrays.toString(sArray)); System.out.println("Number of Special Characters = " + countSpecial(sArray)); } public static int countSpecial(String strings[]) { int count = 0; for (int i = 0; i < strings.length; i++) { for (int j = 0; j < strings[i].length(); j++) { char c = strings[i].charAt(j); if (!Character.isLetterOrDigit(c) && !Character.isWhitespace(c)) count++; } } return count; } }
© 2015 CS160 Colorado State University. All Rights Reserved.