Simple handling of strings

String Handling
In actual development work, handling strings is the most common programming task.
This topic is to ask the program to process the string entered by the user. The specific rules are as follows:
1. Capitalize the first letter of each word.
2. Separate the numbers and letters with an underscore character (_) to make it clearer
. 3. Adjust the words with multiple spaces in the middle to one space.
For example:
user input:
you and me what cpp2005program
program output:
You And Me What Cpp_2005_program
user input:
this is a 99cat
program output:
This Is A
99_cat No other letters or symbols are included.
Each word is separated by one or more spaces.
It is assumed that the string entered by the user does not exceed 200 characters in length.

    import java.util.Scanner;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
* This topic is to require the program to process the string input by the user. The specific rules are as follows:
*1. Change the first letter of each word to uppercase.
*2. Separate numbers and letters with an underscore character (_) to make it clearer
. *3. Adjust words with multiple spaces in the middle of words to one space.
*We assume that the string entered by the user only contains lowercase letters, spaces and numbers, and does not contain other letters or symbols. Each word is separated by one or more spaces.
*Assume that the string entered by the user does not exceed 200 characters in length.
*/
public class SimpleString {
public static void main(String args[]){
String str="";
str=(new Scanner(System.in)).nextLine();
String []str1=str.split("[ ]+”);
for(int i=0;i

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324488816&siteId=291194637