|
Re: how to insert symbols
|
Posted: Jul 8, 2008 4:16 AM
|
|
Try in this way
public class Latin {
public static void main(String [] str) {
final int N = 10;
System.out.print("------+"); for (int i = 0; i <= N; i++) System.out.print("-----"); System.out.println("-----");
for (int i = 0; i <= N; i++) { System.out.print(String.format("%1$5s",i)+"|"); } System.out.println(); System.out.print("------+"); for (int i = 0; i <= N; i++) System.out.print("-----"); System.out.println("-----");
for (int i = 1; i <= N; i++) { System.out.print(String.format("%1$5s",pad(i)) + "|");
for (int j = 1; j <= N; j++) { System.out.print(String.format("%1$5s",pad(i * j)) + " "); } System.out.println(); }
System.out.print("------+"); for (int i = 0; i <= N; i++) System.out.print("-----"); System.out.println("-----"); }
static String pad(int x) { String s = new String(); if (x < 10) s = " " + x; else if (x < 100) s = " " + x; else s = "" + x; return s; } }
|
|