題目:輸入一行字符,分別統(tǒng)計(jì)出其中英文字母、空格、數(shù)字和其它字符的個(gè)數(shù)。import java.util.*;public class lianxi07 {public static void main(String[] args){int digital = 0;int character = 0;int other = 0;int blank = 0;char[] ch = null;Scanner sc = new Scanner(System.in);String s = sc.nextLine();--------------------------------------------下面的邏輯不太理解-----------------------------------------------ch = s.toCharArray();for(int i=0; i<ch.length; i++) {if(ch >= '0' && ch <= '9') {digital ++;} else if((ch >= 'a' && ch <= 'z') || ch > 'A' && ch <= 'Z') {character ++;} else if(ch == ' ') {blank ++;} else {other ++;}}---------------------------------------------------------------------------------------------------------------------System.out.println("數(shù)字個(gè)數(shù): " + digital);System.out.println("英文字母?jìng)€(gè)數(shù): " + character);System.out.println("空格個(gè)數(shù): " + blank);System.out.println("其他字符個(gè)數(shù):" + other );}}
這個(gè)邏輯性,不好理解能解釋下面。大神???感謝------
qq_小杜_(tái)1
2017-06-09 23:17:17