Menu
Question Index
...

What will be the output of the following program?

public class PowerExample {
    static int i, j, k;
    final int result1 = 0;
    final double result = 1;
    public static void main(String[] args) {
        i = 1;
        j = 2;
        k = 3;
        int val = getResult(i, j, k);
        System.out.println("final result is " + val);
    }

    private static int getResult(int i, int j, int k) {
        int result = getDiv(i, j, k);
        return result;
    }
    private static int getDiv(int i, int j, int k) {
        int result = (getpow(i, 2, result) + getpow(j, 3, result)) / k;
        return result;
    }
    private static int getpow(int i, int j, double result) {
        result = 1;
        for (int k = 0; k < j; k++) {
            result *= i;
        }
        return (int) result;
    }
}


final result is 3
final result is 2
final result is 0
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Multiple Methods In One Class Static Keyword In Java

Read this topic Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App