2个回答
展开全部
是这种效果吗?
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String num = br.readLine();
int aLen = ((num.length())%4==0) ? num.length()/4: num.length()/4+1;
String[] a = new String[aLen];
String result = "";
for(int i = 0; i < aLen; i++) {
int begin = i * 4;
int end = (i*4+4) > num.length() ? num.length() : i * 4 + 4;
a[i] = num.substring(begin, end);
}
for(int i = 0; i < aLen; i++) {
result = result + a[i] + " ";
}
System.out.println(result);
}
2015-12-28
展开全部
import java.util.Scanner;
public class test {
public static void main( String args[] ) {
Scanner sc =new Scanner(System.in);
StringBuilder str =new StringBuilder(sc.next());
sc.close();
for( int i=4; i <= str.length()-1; i += 5 )
{
str.insert(i, ' ');
}
System.out.println(str.toString());
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询