2026-The first letter becomes uppercase (java)

Insert picture description here
Idea : My idea is to grasp the condition of space, and change the case of the first character after the space.

import java.util.*;
public class Main {
    
    
public static void main(String[] args) {
    
    
	Scanner a=new Scanner(System.in);
	while(a.hasNext())
	{
    
    
		String str=a.nextLine();
		StringBuilder string=new StringBuilder();
		for(int i=0;i<str.length();i++)
		{
    
    
			if(i==0)
				string.append((char)(str.charAt(i)-32));
			else if(str.charAt(i)==' ')
				string.append(" "+(char)(str.charAt(i+1)-32));
			else if(str.charAt(i-1)!=' ')
				string.append(str.charAt(i));
		}
		System.out.println(string);
	}
}
}

If there is an error, please correct me.

Guess you like

Origin blog.csdn.net/weixin_45956604/article/details/113825104