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 program to enter the numbers till the user wants and at the end it should display the count of positive, negative and zeros entered. 


View

Write a function that takes in age as input and returns if that person is eligible to vote or not. A person of age > 18 is eligible to vote.


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 to calculate the product of 2 numbers.


View

Write a program to print Fibonacci series of n terms where n is input by user :

0 1 1 2 3 5 8 13 21 ..... 

In the Fibonacci series, a number is the sum of the previous 2 numbers that came before it.


View

Reverse a String (using StringBuilder class) in java.


View

Write an infinite loop using do while condition.


View