Make String first letter capital in java

后端 未结 8 2085
耶瑟儿~
耶瑟儿~ 2020-12-29 04:04

As of now I\'m using this code to make my first letter in a string capital

String output = input.substring(0, 1).toUpperCase() + input.substring(1);
<         


        
相关标签:
8条回答
  • 2020-12-29 04:45
    String out = Character.toUpperCase(inText.charAt(0)) + inText.substring(1).toLowerCase();
    
    0 讨论(0)
  • 2020-12-29 04:49
    public static void main(String[] args) {
        String str = null;
        String outStr = null;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a String: ");
        str = sc.nextLine();
        //c= Character.toUpperCase(str.charAt(0));
    
        for(int i=0; i< (str.length());i++){
    
            if(str.charAt(i)==' '){
    
                outStr= outStr.substring(0,i+1)+str.substring(i+1,i+2).toUpperCase()+str.substring(i+2);
    
            }else if(i==0){
    
                outStr=str.substring(0,1).toUpperCase()+str.substring(1);
    
            }
        }
        System.out.println("STRING::"+outStr);
    }
    
    0 讨论(0)
提交回复
热议问题