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
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
(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