杭电 2026 ( 首字母变大写 ) java

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str = sc.nextLine();
            char arrc[] = str.toCharArray();
            if (str.length() < 100) {
                for (int i = 0; i < arrc.length; i++) {

                    if (i == 0) {
                        if (arrc[i] <= 65 || arrc[i] >= 90) {
                            arrc[i] = (char) (arrc[i] - 32);
                        }
                    }
                    if (arrc[i] == 32) {
                        if (arrc[i + 1] <= 65 || arrc[i + 1] >= 90) {

                            arrc[i + 1] = (char) (arrc[i + 1] - 32);
                        }

                    }
                }
                for (int i = 0; i < arrc.length; i++) {
                    System.out.print(arrc[i] + "");
                }
                System.out.println();

            }
        }
    }
}

你可能感兴趣的:(java解题-杭电水题100道)