Finding all uppercase letters of a string in java

前端 未结 10 1064
后悔当初
后悔当初 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:17

    for(int y = 0; y <= z; y++){
    

    should be

    for(int y = 0; y < z; y++){
    

    Remember array index starts from ZERO.

    String length returns

    the number of 16-bit Unicode characters in the string

    Because loop started from ZERO, loop should terminate at length-1.

提交回复
热议问题