Tuesday, July 30, 2013

JAVA PROGRAM TO GENERATE MULTIPLICATION TABLE



Example-1: To print the multiplication table for the particular number.
(consider number is 4)-

public class multiply
{
public multiply(int a) //parameterized constructor
{
for(int i=1;i<=10;i++)
System.out.println(a+" * "+i+" = "+(a*i));
}

public static void main(String[] s)
{
multiply m=new multiply(4); //calling constructor with the value 4 (parameterized contructor)
}
}

Note: after compiling and using "java" statement, if anyone get "Error: could not find or load main class", then use "java -cp . filename".

Output:
javac multiply.java
java multiply


No comments:

Post a Comment

Animated Social Gadget - Blogger And Wordpress Tips