Question 35 : Write a program in Java to print the multiplication table of a number up to n (entered by the user) :
Specimen (shown for 10 up to 20) :
10x1=10
10x2=20
10x3=30
10x4=40
10x5=50
10x6=60
10x7=70
10x8=80
10x9=90
10x10=100
10x11=110
10x12=120
10x13=130
10x14=140
10x15=150
10x16=160
10x17=170
10x18=180
10x19=190
10x20=200
Java Program :
public class multiplication_table_till_n_times
{
public static void main(int a,int n)
{
int i,d;
System.out.println("Your multiplication table is as follows : \n");
for (i=1;i<=n;i++)
{
d=a*i;
System.out.println(a+"x"+i+"="+d);
}
}
}
Specimen (shown for 10 up to 20) :
10x1=10
10x2=20
10x3=30
10x4=40
10x5=50
10x6=60
10x7=70
10x8=80
10x9=90
10x10=100
10x11=110
10x12=120
10x13=130
10x14=140
10x15=150
10x16=160
10x17=170
10x18=180
10x19=190
10x20=200
public class multiplication_table_till_n_times
{
public static void main(int a,int n)
{
int i,d;
System.out.println("Your multiplication table is as follows : \n");
for (i=1;i<=n;i++)
{
d=a*i;
System.out.println(a+"x"+i+"="+d);
}
}
}
correct program!!!!i have also done in this way!
ReplyDelete