当前位置:网站首页>OJ daily practice - filter extra spaces

OJ daily practice - filter extra spaces

2022-06-22 23:33:00 KJ. JK

Problem description :

There may be multiple consecutive spaces in a sentence , Filter out the extra space , Just leave a space .

Input
a line , A string ( Length not exceeding 200), There are no spaces at the beginning and the end of a sentence .

Output
Filtered sentences .

 Insert picture description here


Java Code :

import java.util.Scanner;
public class Main {
    
	public static void main(String[] args) {
    
		Scanner in=new Scanner(System.in);
		String a=in.nextLine();
		String b=a.replaceAll("\\s+"," ");
		String c[]=b.split(" ");
		for(int i=0;i<c.length;i++) {
    
			System.out.print(c[i]+" ");
		}
	}
}

author :KJ.JK
If the article is helpful to you , Welcome to praise or star, Your support is the greatest encouragement to the author , The shortcomings can be corrected in the comments section , Communication and learning

原网站

版权声明
本文为[KJ. JK]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206222059454676.html