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

 

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

Write a method that accepts a number 'firstSquare' that will be the lower number to square. You will also consider the square of the next higher integer. Return the difference between the higher number squared and the lower number ('firstSquare') squared. For example, if 'firstSquare' is 4, you will return 9 because 4 squared is 16 and 5 squared is 25. 25-16=9. So the difference is 9. There are some SERIOUS restrictions on this problem! The ONLY data type you are allowed to use anywhere in your code is 'int'. You cannot use 'long' or 'real' or 'double'! You cannot use an array. Just 'int'. This is a SERIOUS restriction because some of the 'firstSquare' numbers will be greater than the maximum integer value if you square them. So, you must find a way to get solutions to a problem involving squares without actually finding those squares! As a precondition, you may assume that 'firstSquare' is non-negative. As always, look at the test data for examples.


test2023_11_02_HL_consecutiveSquaresDifference(1073741819) → 2147483639
test2023_11_02_HL_consecutiveSquaresDifference(987751077) → 1975502155
test2023_11_02_HL_consecutiveSquaresDifference(45461587) → 90923175

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

public int test2023_11_02_HL_consecutiveSquaresDifference(int firstSquare) { }

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: 290

Copyright Nick Parlante 2017 - privacy