public class nombre_majuscule_minuscule {このコードの実行:
public static void main(String[] args) {
String string="Java is a programming language"+
"Sun Microsystemsによって作成されたオブジェクト指向";
int nbr_min = nbr_min(文字列);
int nbr_maj = nbr_maj(文字列);
System.out.println("小文字の数 "+nbr_min);
System.out.println("大文字の数字"+nbr_maj);
}
private static int nbr_maj(文字列文字列) {
int counter=0;
for(int i = 0; ichar ch = string.charAt(i);
if(Character.isLowerCase(ch))
counter++;
}
リターンカウンター。
}
private static int nbr_min(文字列文字列) {
int counter=0;
for(int i = 0; ichar ch = string.charAt(i);
if(Character.isUpperCase(ch))
counter++;
}
リターンカウンター。
}
}
小文字の番号 4
大文字の番号 68
private static int nbr_maj_recursive(String string, int i) {メソッド宣言 nbr_min_recursive() メソッド で行われる文字タイプチェックのレベルでのみ変更されます。isLowercase().
/*iが文字列のサイズに達した場合
* return 0
*/
if(string.length()-i==0)
return 0;
/*それ以外の場合は、次の文字をチェックします*/
else{
char ch = string.charAt(i);
if(estUpper(ch))
/*i をインクリメントして 1 つ数える
*大文字*/
return nbr_maj(string, ++i)+1;
}
return nbr_maj(string, ++i);
}
private static int nbr_min_recursive(String string, int i) {メソッド isUppercase() は、isUpperCase().
if(string.length()-i==0)
return 0;
else{
char ch = string.charAt(i);
if(isLowercase(ch)))
return nbr_min(string, ++i)+1;
}
return nbr_min(string, ++i);
}
static boolean isUpperCase(char ch){メソッド isTiny() は、isLowerCase().
int ascii = (int) ch;
//[A..Z]
if((ascii>=65 &&ascii<=90)
//アクセント付き文字
||(ascii>=192 &&ascii<=223))
return true;
return false;
}
static boolean isLowercase(char ch){
int ascii = (int) ch;
//[a..z]
if((ascii>=97 &&ascii<=122)
//アクセント付き文字
||(ascii>=224 &&ascii<=255))
return true;
return false;
}
public void compter_majuscules_java8() {小文字を数えるには、次のようにします:
String phrase = "This is a test";
long counter = phrase.chars().filter(Character::isUpperCase).count();
}
public void compter_minuscules_java8() {
String phrase = "This is a Test";
long counter = phrase.chars().filter(Character::isLowerCase).count();
}
public void compter_majuscules_java8() {小文字を数えるには、次のようにします:
String phrase = "This is a test";
long counter = CharMatcher.JAVA_UPPER_CASE.retainFrom(phrase).length();
}
public void compter_minuscules_java8() {
String phrase = "This is a Test";
long counter = CharMatcher.JAVA_LOWER_CASE.retainFrom(phrase).length();
}
Please disable your ad blocker and refresh the window to use this website.