所以我一直在用Java編寫一小段代碼,它從用戶輸入大寫,小寫和其他部分(如空格,數字,甚至是括號),然後返回每個用戶都有很多。大寫字母,小寫字母和其他計數器
我現在的問題是說我在「你好」的位置放置了「你好」後面的「o」後停止計數點。所以在第一個字之後。
代碼
import java.util.Scanner;
public class Example {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int upper = 0;
int lower = 0;
int other = -1;
int total = 0;
String input;
System.out.println("Enter the phrase: ");
input = scan.next();
for (int i = 0; i < input.length(); i++) {
if (Character.isUpperCase(input.charAt(i))) upper++;
if (Character.isLowerCase(input.charAt(i))) lower++;
else other++;
total = upper + lower + other;
}
System.out.println("The total number of letters is " + total);
System.out.println("The number of upper case letters is " + upper);
System.out.println("The number of lower case letters is " + lower);
System.out.println("The number of other letters is " + other);
}
}
謝謝你,我甚至沒有看到的一切事物。 – 2014-11-25 13:22:26