Quick actions

cmd+k|ctrl+k

Navigation

Languages

Week1Mock1MCQ38

Snippet info

Language

Java

Visibility

public

Author

masterhun

Created

2024-04-07T19:32:57.415958Z

Updated

2024-04-07T20:19:01.958267Z



// import java.util.*;


public class Main {
    
    /*

    Answer Key: (E) Both (B) and (C) 

    (B) Change lines 3 and 4 to: 
	3	if (x == 1)
	4		return b;

    (C) Change line 6 to: 
	6	return b * pow(b, x - 1); 
	// Typo: mystery should be pow 

    */ 
    
    
    public static double pow(double b, int x)
    {
    	if (x == 1)
    		return b;
    	else
    		return b * pow(b, x - 1);
    }

    public static void main(String[] args) {
        
        // Harbor, Week 1, Mock 1, PR_PracticeTest_1.pdf
        
        // AP CS A 
        
        // MCQ 38
        
        int power = 3; 
        double b = 2.0; 
        System.out.println(pow(b, power)); 
        // Output: 2.0^3 = 8.0 







    }
}
INFO