Write a function to multiply 2 numbers.


import java.util.*;

 

public class Functions {

 

   //Multiply 2 numbers

   public static int multiply(int a, int b) {

       return a*b;

   }

   public static void main(String args[]) {

       Scanner sc = new Scanner(System.in);

       int a = sc.nextInt();

       int b = sc.nextInt();

 

       int result = multiply(a, b);

       System.out.println(result);

   }

}



Share to whatsapp

More Questions from Java Basic Codes Module 0

Write a function to calculate the factorial of a number.


View

Take an array of Strings input from the user & find the cumulative (combined) length of all those strings.


View

Write a function to multiply 2 numbers.


View

Write an infinite loop using do while condition.


View

Find the maximum & minimum number in an array of integers.

[HINT : Read about Integer.MIN_VALUE & Integer.MAX_VALUE in Java]


View

Write a function that calculates the Greatest Common Divisor of 2 numbers.


View

Reverse a String (using StringBuilder class) in java.


View