Given float variables x1,x2,y1,y2, and m, write a code segment to find the slope of a line through the two points (xv,y1) and (x2,y2). Use the formula
m = y2-y1/x2-x1
to determine the slope of the line. If x1 equals x2, the line is vertical and the slope is undefined. The segment should display the slope with an appropiate label. If the slope is undefined, it should display the message "Slope undefined."
Code
int y2 = 5;
int y1 = 3;
int x2 = 4;
int x1 = 4;
if(x2-x1!=0){
int m = (y2-y1)/(x2-x1);
}
else{
print ("Slope undefined");
}
Text book name : Programming and Problem solving with Java second edition
Author : Nell Dale and Chip Weems
ISBN : 978-0-7637-3402-2
ไม่มีความคิดเห็น:
แสดงความคิดเห็น