Advertisement
satriafu5710

Kali Dua Bilangan Rekursi Java

Dec 5th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. package com.tutorial;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner userInput = new Scanner(System.in);
  9.  
  10.         int a, b;
  11.         System.out.println("\t Kali 2 Buah Bilangan \n");
  12.  
  13.         System.out.print("\n Masukkan Angka     : ");
  14.         a = userInput.nextInt();
  15.  
  16.         System.out.print(" Mau diKali Berapa  : ");
  17.         b = userInput.nextInt();
  18.  
  19.         System.out.print("\n Hasil Perkaliannya : " + kali(a, b));
  20.     }
  21.  
  22.     public static int kali(int a, int b) {
  23.         if (b == 1) {
  24.             return a;
  25.         } else {
  26.             return a + kali(a, b - 1);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement