Answers for "multiple recursion"

0

2 multiples recursion

import java.util.Scanner;

public class multipied {
    public static Scanner scanner = new Scanner (System.in);
    public static void main(String[] args) {
        System.out.println("Enter int");
        int n = scanner.nextInt();
        int sum = 1;
        System.out.println("For loop");
        for(int i = 0 ; i < n ; ++i ){
            if(n == 0){
                System.out.println(sum+'\n');
                break;
            }
            sum*=2;
        }
        System.out.println(sum);
        int r = multipied(n);
        System.out.println("\nRecursive");
        System.out.println(r);
        ;

    }

    public static  int multipied(int n){

        if(n ==0)
            return 1;

        return 2 * multipied(n-1);
    }

}
Posted by: Guest on July-30-2021
0

2 multiples recursion

import java.util.Scanner;

public class multipied {
    public static Scanner scanner = new Scanner (System.in);
    public static void main(String[] args) {
        System.out.println("Enter int");
        int n = scanner.nextInt();
        int sum = 1;
        System.out.println("For loop");
        for(int i = 0 ; i < n ; ++i ){
            if(n == 0){
                System.out.println(sum+'\n');
                break;
            }
            sum*=2;
        }
        System.out.println(sum);
        int r = multipied(n);
        System.out.println("\nRecursive");
        System.out.println(r);
        ;

    }

    public static  int multipied(int n){

        if(n ==0)
            return 1;

        return 2 * multipied(n-1);
    }

}
Posted by: Guest on July-30-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language