26.1.1.4 複数表示

これまでは表示が1行だけでしたが,たくさん並べることもできます.

class Jstart2 
{
    public static void main(String argv[]) { 
        System.out.println("As I was going to St. Ives,");
        System.out.println(" I met a man with seven wives,");
        System.out.println("  Each wife had seven sacks,");
        System.out.println("   Each sack had seven cats,");
        System.out.println("    Each cat had seven kits,");
        System.out.println("     Kits, cats, sacks, and wives,");
        System.out.println("How many were there going to St. Ives?");
    }
}

fileJstart2.java

それぞれの出力指令の末尾のセミコロンを忘れないで下さい.二重引用符の対応関係も大切です.

また,printlnの代りにprintを使うと,最後に改行をしません.「ln」は「line」の意味です.これを用いると,1行の内容を何回かに分けて出力することができます.

class Jstart3 {
    public static void main(String argv[]){
	System.out.print("Bye-bye "); //Bye-bye
	System.out.print("20 ");      //Bye-bye 20
	System.out.print("century!"); //Bye-bye 20 century!
	System.out.println();         //これで改行
    }
}

fileJstart3.java (iso-2022-jp)

最後のSystem.out.println();は,改行だけを指示します.結果は以前と同様で

Bye-bye 20 century!

となります.