Advertisement
cd62131

MultiplicationTable

Jul 11th, 2014
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.58 KB | None | 0 0
  1. import java.util.Formatter;
  2.  
  3. public class MultiplicationTable {
  4.   public static void main(String[] args) {
  5.     StringBuilder sb = new StringBuilder();
  6.     Formatter f = new Formatter(sb);
  7.     f.format(" |");
  8.     for (int i = 1; i < 10; i++) f.format("%3d", i);
  9.     f.format("\n");
  10.     for (int i = 0; i < 3 * 9 + 2; i++) f.format("-");
  11.     f.format("\n");
  12.     for (int i = 1; i < 10; i++) {
  13.       f.format("%d|", i);
  14.       for (int j = 1; j < 10; j++) {
  15.         f.format("%3d", i * j);
  16.       }
  17.       f.format("\n");
  18.     }
  19.     System.out.println(f);
  20.     f.close();
  21.   }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement