Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将多个System.out.prinln()压缩为一个_Java - Fatal编程技术网

Java 将多个System.out.prinln()压缩为一个

Java 将多个System.out.prinln()压缩为一个,java,Java,我有 我需要将那些System.out.println压缩成一个单独的文件。您可以尝试使用String.format 您可以使用\n输出新行。也可以看看String.format.allow:。。。。。。。。。。。为什么?谢谢你,提洛!我不能活了,我忘了。我相信你最好的选择是 for( int x = 0; x < rp.studentRecords.length; x++){ System.out.println("Student name: " +rp.

我有


我需要将那些System.out.println压缩成一个单独的文件。

您可以尝试使用String.format


您可以使用\n输出新行。也可以看看String.format.allow:。。。。。。。。。。。为什么?谢谢你,提洛!我不能活了,我忘了。我相信你最好的选择是
        for( int x = 0; x < rp.studentRecords.length; x++){
        System.out.println("Student name: " +rp.studentRecords[x].getName());
        System.out.println("Major: "+ rp.studentRecords[x].getClass().getName());
        System.out.println("Age: "+ rp.studentRecords[x].getName());
        System.out.println("Year " +rp.studentRecords[x].getYear());
        System.out.println("Credits Earned: "+ rp.studentRecords[x].getCredits());
        System.out.println("Remaining Credits: "+ rp.studentRecords[x].getRemainingCredits());
        System.out.println("-------");
    }
String output = String.format ("Name: %s\nMajor: %s\nAge: %s", 
  rp.studentRecords[x].getName(),
  rp.studentRecords[x].getClass().getName(),
  rp.studentRecords[x].getAge());

// then print it out
System.out.println (output);