Finding all uppercase letters of a string in java

前端 未结 10 1156
后悔当初
后悔当初 2021-01-12 14:28

So I\'m trying to find all the uppercase letters in a string put in by the user but I keep getting this runtime error:

Exception in thread \"main\" java.lan         


        
10条回答
  •  梦谈多话
    2021-01-12 15:16

    public class Cama {
    
    public static void main(String[] args) {
        String camal = "getStudentByName";
        String temp = "";
        for (int i = 0; i < camal.length(); i++) {
            if (Character.isUpperCase(camal.charAt(i))) {
                System.out.print(" " + Character.toLowerCase(camal.charAt(i)));
            } else if (i == 0) {
                System.out.print(Character.toUpperCase(camal.charAt(i)));
            }else{
                System.out.print(camal.charAt(i));
            }
        }
    }
    }
    

提交回复
热议问题