我的问题可能根本不能很好地解释这个问题,但我遇到的是我能够得到一个“盒子”的字符串的第一行,如这里的示例所示:https ://docs.google .com/open?id=0B_ifaCiEZgtcVUx3c2c1VWs2NEE
这是我现在的主要代码:
import java.util.Scanner;
import static java.lang.System.*;
public class LineBreaker
{
private String line;
private int breaker;
public LineBreaker()
{
this("",0);
}
public LineBreaker(String s, int b)
{
line = s;
breaker = b;
}
public void setLineBreaker(String s, int b)
{
line = s;
breaker = b;
}
public String getLine()
{
return line;
}
public String getLineBreaker()
{
String box ="";
Scanner scan = new Scanner(line);
//scan.useRadix(breaker);
//while (scan.hasNext()){
for(int i = 0; i < breaker; i++){
box += scan.next();
}box += "\n";
//}
return box;
}
public String toString()
{
return line + "\n" + getLineBreaker();
}
}
它是相关的跑步者类:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
import static java.lang.System.*;
public class Lab12f
{
public static void main(String args[]) throws IOException
{
LineBreaker test = new LineBreaker("1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9", 4);
out.println(test);
test.setLineBreaker("t h e b i g b a d w o l f h a d b i g e a r s a n d t e e t h", 2);
out.println(test);
test.setLineBreaker("a c o m p u t e r s c i e n c e p r o g r a m", 7);
out.println(test );
test.setLineBreaker("i a m s a m i a m", 2);
out.println(test);
}
}
目前我的输出是这样的:
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
1234
thebig badwolfhadbigea rsand 牙齿
th
计算机科学计划
计算机
伊斯兰教义
我