参考一下TextArea的实现~
呵呵 乱说的~
呵呵 乱说的~
解决方案 »
- 数据库系统设计的一个问题
- 怎样输出List下的sublist内容 我写的不输出 谢谢各位了
- 各位大大帮忙解决java.lang.NoClassDefFoundError,急!急!急!
- 关于JButton
- 受不了了!超级菜鸟问题!最后50分了!!绝对超级菜鸟问题~
- 大家注意了没有,在swing类库中,大部分组件都实现了Accessible这个接口,请问该接口是做什么的?
- 怎么运行编译后的.class文件呀!??在线等。
- 布局管理setLayout() && 设置位置setLocation() ???
- ant在win2000中配置问题
- Class.forName("jdbc.odbc.JdbcOdbcDriver")的问题?
- 谁能告诉我COGNOS,SAS都是什么?
- 想学JAVA但是一点不懂,求助!
public class StringConvert {
public final static int d_rows = 4;
public StringConvert() {
}
public String[] convert( String s , int rows) {
if( null == s || 0 >= rows )
return null;
String[] result = new String[rows];
try {
for( int i = 0; i < rows ; i ++ ) {
int j = 0;
result[i] = "";
while( (i + rows*j) < s.length() ) {
result[i] += s.charAt( i + rows*(j++) );
}
if( 0 == result[i].length() )
break; //no more chars here
}
}
catch ( Exception e ) { e.printStackTrace(); }
return result;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String source = null;
int rows = StringConvert.d_rows;
if( 0 == args.length ) {
source = "hahahahaha, this is a test";
}
else if ( 1 == args.length ) {
source = args[0];
}
else if ( 2 == args.length ) {
source = args[0];
try {
rows = (new Integer(args[1])).intValue();
}
catch ( Exception e ) {
System.out.println("variable error, illegal rows");
System.exit( 1 );
}
}
else {
System.out.println("Use: java ts SourceString");
System.exit( 2 );
}
System.out.println("***********rows =" + rows +"*****************");
System.out.println("***********original string*************");
System.out.println(source);
System.out.println("****************************************");
System.out.println();
StringConvert sc = new StringConvert();
String[] result = sc.convert( source, rows);
if( null == result) {
System.out.println("Convert error");
System.exit( 3 );
}
System.out.println("***********result string*************");
for( int i = 0; i < result.length ;i++ ) {
if( null != result[i] )
System.out.println( result[i]);
}
System.out.println("****************************************");
}
}