Created
March 11, 2021 14:11
-
-
Save Loliver1224/962e3ea1c9360bf5c428229253bb66bf to your computer and use it in GitHub Desktop.
Javaにおけるprintlnの簡潔化
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyPrint { | |
public static void main(String[] args) { | |
println("Hello, world!"); | |
} | |
void print(Object line) { | |
System.out.print(line); | |
} | |
void println(Object line) { | |
System.out.println(line); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
public class PrintWriterTest { | |
// System.out.println()はデフォでオートフラッシュが有効なため低速 | |
// PrintWriterを用いて自動フラッシュしないようにする | |
static PrintWriter out = new PrintWriter(System.out); | |
static void myout(Object t){out.println(t);} | |
static void flush(){out.flush();} | |
public static void main(String[] args) { | |
println("Hello"); | |
// プログラム終了前にフラッシュを忘れないように! | |
flush(); | |
// out.close()でも暗黙的にflushが呼ばれる | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment