id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > test2021_06_03_P1SL_power
prev  |  next  |  chance

Write a method that returns the square or the cube of a positive integer 'num'. The string 'power' will either contain "squared", "cubed", or anything else. If it contains "squared" return the square of 'num'. If it contains "cubed" return the cube of 'num'. If it contains anything else, return 0 as an error code. NOTE: You are NOT allowed to use maps, functional programming, or array lists. You are NOT allowed to have any nested loops or nested recursion. You are NOT allowed to make a giant array that is way longer than the input parameter arrays. Kyle, you must resist your natural impulses!


test2021_06_03_P1SL_power(6, "cubed") → 216
test2021_06_03_P1SL_power(5, "squared") → 25
test2021_06_03_P1SL_power(7, "squared") → 49

...Save, Compile, Run (ctrl-enter)

public int test2021_06_03_P1SL_power(int num, String power) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 220

Copyright Nick Parlante 2017 - privacy