For Example
1 2 3 4
2 4 6 8
3 6 9 12
4 8 12 16
10 20 30 40 = Total
import java.awt.*;
import java.util.*;
import java.io.*;
public class MultiplicationTable{
public static void main(String[] args) throws IOException
{
int[][] multtable = new int[11][11];
System.out.print( "Enter your number: " );
java.io.BufferedReader maankilanz = new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );
String input = maankilanz.readLine();
int n = Integer.parseInt( input );
System.out.print("*");
for (int a = 1; a <= n; a++) {
System.out.print("\t" + a);
}
System.out.println(" ");
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
multtable[i][j] = i * j;
}
}
System.out.print("\t");
System.out.print("-----------------------------------------------------------------------------");
System.out.println("");
for (int i = 1; i <= n; i++) {
System.out.print(i + "|");
for (int j = 1; j <= n; j++)
{
System.out.print("\t" + multtable[i][j]);
}
System.out.println("");
System.out.println("");
}
}
}
This post has been edited by baavgai: 30 September 2012 - 03:03 AM
Reason for edit:: moved and tagged, java ain't python

New Topic/Question
Reply



MultiQuote




|