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

 

gaurav.gupta@mq.edu.au variables > getX
prev  |  next  |  chance

Define a function that when passed the coordinates of two points (x1, y1) and (x2, y2) through which a line passes and another value (y3), returns the x-coordinate of the point on the line when y = y3.

You may assume the line is not vertical (because then we'll need conditions).

Just like the perimeter function (https://codingbat.com/prob/p244438), the complexity of this question is in the research and analysis, not the implementation.

You may assume the x-coordinate corresponding to y3 is an integer. That is, the line passes through (x3, y3) where x3 and y3 are both integers.


getX(2, 6, 4, 12, 30) → 10
getX(5, 4, 20, 5, 6) → 35
getX(2, 6, 4, 12, -12) → -4

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

int getX(int x1, int y1, int x2, int y2, int y3) { }

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

Copyright Nick Parlante 2017 - privacy