about | help | code help+videos | done | prefs |
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) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 220
Copyright Nick Parlante 2017 - privacy