Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

exponet

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+'
');
                break;
            }
            sum*=2;
        }

        if (n >= 31){
            System.out.println(sum-1);
            int r = multipied(n);
            System.out.println("
Recursive");
            System.out.println(r-1);
        }else{
            System.out.println(sum);
            int r = multipied(n);
            System.out.println("
Recursive");
            System.out.println(r);
        }



    }

    public static  int multipied(int n){
        int ans;
        if(n == 0)
            return 1;
        else if(n%2 == 0){
            int k = multipied(n/2);
            ans = k*k;
        }
        ans= 2 * multipied(n-1);

        return ans ;
    }

}


Comment

exponet

public class Recursion {
    public static void main(String[] args) {
        int[] arr = {23,21,321,312,31,23,12,312,312,312,3,18,200000,1};
        int arrSum = 0;
        arrSum= sigma(arr,arr.length-1);

        int sum;
        sum = sigma(arr.length);
        System.out.println("Sum of Array Elements:");
        System.out.println(arrSum+"
");
        System.out.println("sigma n ==> (Arr.length) 
"+arr.length+"
"+ sum);
    }


    public static int sigma(int n){
        if(n<=0)
            return n;

        return n + sigma(n-1);


    }

    public static int sigma(int[] arr, int l){

        if(l == 0)
            return arr[l];

        return arr[(l)] + sigma(arr,l-1) ;
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: plug and chug 
Java :: java gui bank account program 
Java :: how to extract word from string in java 
Java :: coin flip random java 
Java :: Note: flutterpluginspathproviderPathProviderPlugin.java uses unchecked or unsafe operations. 
Java :: syntax for new module creation in java 
Java :: Deque interface in Java 
Java :: spring secutiry urls redirecting 
Java :: XmlRootElement Object to String 
Java :: int in double umwandeln java 
Java :: java awt bild einfügen 
Java :: Picked up _JAVA_OPTIONS: -Xmx256M intillij 
Java :: csv file data structure java 
Java :: time complexity of indexof java 
Java :: java equals on recursive apache commons 
Java :: constraint layout not matching parent in netsted scrollview 
Java :: EXPECTTIONS JAVA 
Java :: lelen suratlari ramkasidagi oltinlar 
Java :: java reverse a word 
Java :: print jtable in java 
Java :: set jtextfield max length 
Java :: call method without creating object java 
Java :: para que sirve getcontentpane en java 
Java :: Add Future Date in AndroidStudio 
Java :: java print data and check in android studio 
Java :: ujava saum of positive integers 
Java :: java calculator joptionpane 
Java :: opencv copy image java 
Java :: java notnull returns null 
Java :: how to get index of while loop java 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =