public class TestString { public static void main(String[] args) { String s1 = "AaaaABBBBcc&^%adfsfdCCOOkk99876 _haHA"; char cr; int a = 0, b = 0, c = 0; for(int i=0; i<s1.length(); i++) { cr = s1.charAt(i); if(cr >= 'a' && c<= 'z'){ b++; } else if(cr >= 'A' && c<= 'Z') { a++; } else { c++; } } for(int i=0; i<s1.length(); i++){ cr = s1.charAt(i); if(Character.isLowerCase(cr)) { a++; } else if(Character.isUpperCase(cr)) { b++; } else { c++; } } System.out.println("字串共有" + s1.length() + "個字"); System.out.println("大寫字母數有:" + a + "個"); System.out.println("小寫字母數有:" + b + "個"); System.out.println("其他符號有:" + c + "個"); System.out.println(); String s2 = "sunjavahpjavaokjavajjavahahajavajavagoodjava"; String s3 = "java"; int index = -1, count = 0; while((index = s2.indexOf(s3)) != -1) { s2 = s2.substring(index + s3.length()); count ++; } System.out.println("共找到\"" + count + "\"個java字串"); }//main end }//class end |
public class TestCase { public static void main(String[] args) { double[][] d; String s = "1,2;3,4,5;6,7,8"; String[] s1 = s.split(";"); for(int i=0; i<s1.length; i++) { d = new double[s1.length][]; String[] s2 = s1[i].split(","); for(int j=0; j<s2.length; j++){ d[i] = new double[s2.length]; d[i][j] = Double.parseDouble(s2[j]); System.out.print(d[i][j] + " "); } System.out.println(); } } } |
全站熱搜
留言列表