我现在正在做一个Java项目,并且觉得StringBuffer在执行这个特定任务时会有很多帮助,我正在"构建"Matrix的字符串表示:
/**
* Returns a String representation of the Matrix using the getIJ getter
* function. You should use MaF.dF to format the double numbers to a
* sensible number of decimal places and place the numbers in columns.
*
* @return A String representation of the Matrix
*/
public String toString() {
//String stringBuilder = new String
StringBuffer beep = new StringBuffer;
for(i=0; i<m-1; i++){
for(j=0; j<n-1; j++){
}
// You need to fill in this method
}
Run Code Online (Sandbox Code Playgroud)
我已经在Java程序中尝试了它本身似乎没问题,但后来我在线尝试了一些示例Java程序并且没有编译.是StringBuffer内置于Java,还是需要导入包?我不允许导入该项目的任何包.
另外,如果有人能告诉我MaF.dF究竟是什么?如何使用?我认为这是MaInput的一部分,我在网上找不到任何东西.
StringBuffer 被内置到Java,你不需要输入任何包.(它的包装是java.lang"自动"导入的.)
请参阅:http://docs.oracle.com/javase/7/docs/api/java/lang/StringBuffer.html
检查下面的代码.它运行没有任何导入.
public class StringBufferUse {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer();
sb.append("a");
sb.append("b");
sb.append(123);
System.out.println(sb.toString()); /* prints "ab123" */
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1105 次 |
| 最近记录: |