PrintWriter: print(int i) : PrintWriter « java.io « Java by API






PrintWriter: print(int i)

 
import java.io.FileWriter;
import java.io.PrintWriter;

public class Main {
  public static void main() throws Exception{
    PrintWriter pw = new PrintWriter(new FileWriter("dice.txt"));
    for (int i = 1; i <= 1000; i++) {
      int die = (int) (1 + 6 * Math.random());
      pw.print(die);
      pw.print(' ');
      if (i % 20 == 0)
        pw.println();
    }
    pw.println();
    pw.close(); // Without this, the output file may be empty
  }
}

   
  








Related examples in the same category

1.new PipedWriter()
2.new PrintWriter(BufferedWriter, boolean autoFlush)
3.new PrintWriter(Writer out)
4.PrintWriter: close()
5.PrintWriter: print(char c)
6.PrintWriter: println(Object x)
7.PrintWriter: println(String x)
8.PrintWriter: println(char x)
9.PrintWriter: println(double x)
10.PrintWriter: println(float x)
11.PrintWriter: println(int x)
12.PrintWriter: println(long x)
13.PrintWriter: println()
14.Writer: write(char[] cbuf)