This Java program takes two integer inputs from the user and calculates their product using a recursive function multiple_numbera().
Overall, this program recursively calculates the product of two integers entered by the user using the multiple_numbera() function.
import java.util.*; public class Multiple_TwoNumbers { public static int multiple_numbera(int n1, int n2) { if (n2 == 0) return 0; if (n2 > 0) return (n1 + multiple_numbera(n1, n2 - 1)); if (n2 < 0) return -multiple_numbera(n1, -n2); return -1; } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the Number 1 : "); int n1 = input.nextInt(); System.out.print("Enter the Number 2 : "); int n2 = input.nextInt(); System.out.println("Multiply of Two Numbers : "+multiple_numbera(n1, n2)); } }
Enter the Number 1 : 19 Enter the Number 2 : 31 Multiply of Two Numbers : 589
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions