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

时间:2016-04-06 02:44:43

标签: java

我有

$(document).ready(function () {
    var links = [
'swfs/#1%20(Special%20Japanese%20Extended%20Dance%20Mix).swf',
'swfs/$D6.swf',
'swfs/(MAD)%20Huh.swf'
];

 var displaytext = [
'#1 (Special Japanese Extended Dance Mix)',
'$D6',
'(MAD) Huh'
];

var c = 0
    var flashmovie, test, temp;

    function init() {
        flashmovie = document.getElementById('flashmovie');
        document.getElementById('back').onclick = function () {
            if (c == 0) {
                c = links.length;
            }
            c--
            displayFiles();
            download();
        }

        document.getElementById('next').onclick = function () {
            if (c == links.length - 1) {
                c = -1;
            }
            c++;
            displayFiles();
            download();
        }

        document.getElementById('rand').onclick = function () {
            temp = c;
            while (c == temp) {
                c = Math.floor(Math.random() * links.length);
            }
            displayFiles();
            download();
        }
    }

    function displayFiles() {

        test = links[c].substring(links[c].lastIndexOf('.') + 1, links[c].length);
        document.getElementById('title').innerHTML = displaytext[c];

        flashmovie.innerHTML =
            '<object type="application/x-shockwave-flash" data="' + links[c] + '">' +
            '<param name="movie" value="' + links[c] + '">' +
            '<\/object>';
    }

    function download() {

            document.getElementById('downLink').setAttribute('href', links[c]);
        }


    window.addEventListener ?
        window.addEventListener('load', init, false) :
        window.attachEvent('onload', init);
});`

我需要将那些System.out.println()压缩成一个。

1 个答案:

答案 0 :(得分:3)

您可以尝试使用String.format之类的

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);