java算法编程
从键盘输入一字符串,将其1,4,7....字符拼接成字符串1,将2,5,8....字符拼接成字符串2, 将第3,6,9....字符拼接成字符串3然后依次输出。输出结果为:123456789用java编程哪位大神会 import java.io.*;
public class Test{
public static void main(String[] args){
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader buff=new BufferedReader(isr);
String str=null;
try{
str=buff.readLine();
}catch(IOException e){
System.out.println("错误信息为:"+e.getMessage());
}
StringBuffer s1=new StringBuffer();
StringBuffer s2=new StringBuffer();
StringBuffer s3=new StringBuffer();
for(int i=0;i<str.length();i+=3){
s1=s1.append(str.charAt(i));
s2=s2.append(str.charAt(i+1));
s3=s3.append(str.charAt(i+2));
}
System.out.println(s1.toString());
System.out.println(s2.toString());
System.out.println(s3.toString());
}
}
}
成功运行
页:
[1]