Advertisement
cd62131

Set and Print

Jan 26th, 2014
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.51 KB | None | 0 0
  1. import java.io.PrintWriter;
  2. import java.io.Writer;
  3.  
  4. public class SetAndPrint {
  5.   private int val;
  6.   private Writer w;
  7.  
  8.   public SetAndPrint(Writer w) {
  9.     this.w = w;
  10.   }
  11.  
  12.   public void setVal(int val) {
  13.     this.val = val;
  14.     try {
  15.       w.write(Integer.toString(this.val));
  16.       w.write("\n");
  17.       w.flush();
  18.     }
  19.     catch (Exception e) {
  20.     }
  21.   }
  22.  
  23.   public static void main(String[] args) {
  24.     SetAndPrint s =
  25.       new SetAndPrint(new PrintWriter(System.out));
  26.     s.setVal(3);
  27.   }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement