输入一组字符串,直到碰到end为之。将其中字符串长度是3的倍数的字符串使用空格拼接起来,并输出
输入格式:
输入一组以空格或者回车换行分隔的字符串,最后一个字符串为end。
输出格式:
将输入字符串中长度是3的倍数的字符串使用空格拼接起来。
注意:行尾有一个空格。
输入样例:
a abc 123456 22 45jd 123456789 end
输出样例:
abc 123456 123456789
答案
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String res = "";
while(true){
String str = scanner.next();
if (str.equals("end")){
break;
}
if (str.length() % 3 == 0){
res += str;
res += " ";
}
}
System.out.println(res);
}
}