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

 

gradient


Equation of a line is given as y = mx + b, where m is the gradient (angle) and b is the y-intercept at x=0. Define a function that given two points through which line passes, returns the gradient of the line. Return null if it is a vertical line (hence, the return type Double) If you don't have the required math knowledge, refer to this page: See this to further understand this: https://www.mathsisfun.com/equation_of_line.html


gradient(10, 5, 7, 4) → 0.3333333333333333
gradient(5, 8, -1, 20) → -2.0
gradient(10, 0, 10, 20) → null

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

Double gradient(int x1, int y1, int x2, int y2) { }

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: 3 Post-solution available

Copyright Nick Parlante 2017 - privacy