multiplication in java code example

Example 1: multiplication without using multiplication in java

public class SumOfElements {
  
  public static void main(String[] args){
    
    int[] a = {1,2,3,4,5};
    
    
    int sum = sumArray(a);
    
   int result = multiply(5,10);
  }
  
  private static int multiply(int i , int j) {
    
    int k = 1;
    int sum = 0;
    
    while(k <= j)
    {
      sum = sum + i;
      k++;
    }

Example 2: multiplication program java

int i,k;
			Scanner sc = new Scanner(System.in);
			System.out.println("Enter the Number for the table: ");

			int n = sc.nextInt();
			for (i=1;i<=10;i++){
				 k = n * i;
				//n + "*" + c + " = " + (n*c))
				System.out.println(n + "*"+ i + " = " + k);	
			}

Example 3: Write a method multiply() in a class Arithmetic

int x = 12;int y = 13;int z = x * y;System.out.println("Multiplication: " + z);

Tags:

Java Example