如何使用java查找斜率的X截距? [英] How to use java to find the X-intercept of a slope?

查看:168
本文介绍了如何使用java查找斜率的X截距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从未使用过Java,我的一位编程朋友给了我这个尝试并习惯了Java。



他给了我test.java文件以及一些用于创建行类的指针。但是,我仍然不知道如何获得斜率或y_int。我假设对于vert我继续使用布尔和if / else语句,但我有点迷失。



这是Test.java:

  public   class 测试{
public static void main( String [] args){
Line line1 = new 行( 0 1 );
Line line2 = new 行( 0 5 2 );
Line line3 = new 行( 1 );
System.out.println( + line is)+ line1.getSlope();
System.out.println( 它是 + line3.vert)+ line3是垂直的();
System.out.println( line3的斜率)+ + line3.getSlope();
}
}







这是Line。 java类

  public   class 行{ 

public class 行{

public double slope;
public double y_int;
public double x_int;
public boolean vert;

public 行( double slope, double y_int){
this .slope = slope;
.y_int = y_int;
vert = false;
}

public 行( double x_int){
slope = Double.NaN;
y_int = Double.NaN;
vert = true;
this .x_int = x_int;
}

public double getSlope(){
返回斜率;
}

public double getY_int(){
return y_int;
}

public boolean isVert(){
return vert;
}
}





我尝试了什么: < br $> b $ b

我想这归结于我不是最好的数学。我显然理解斜率公式,但转换为代码已经证明是困难的。

解决方案

Google搜索是你的朋友。此Google搜索: java X-intercept of a slope - Google搜索 [ ^ ]发现:

* 拦截器 - 在java中找到来自斜率的拦截 - Stack Overflow [ ^ ]

* 斜坡拦截表的Java代码 [ ^ ]

* 以及更多! [ ^

I've never used Java, one of my programming friends gave me this to try and get used to Java.

He gave me the test.java file along with some pointers for making the line class. However, I still don't know how to get the slope or y_int. I assume for vert I continue to use a Boolean and if/else statement but I am a bit lost.

this is the Test.java:

public class Test {
public static void main(String [] args){
    Line line1 = new Line(0,1);
    Line line2 = new Line(0.5,2);
    Line line3 = new Line(1);
    System.out.println("The slope of "+ "line is ")+line1.getSlope();
    System.out.println("It is"+line3.vert)+ "that line3 is vertical"();
    System.out.println("the slope of line3")+ "is "+line3.getSlope();
}
}




this is the Line.java Class

public class Line {

    public class Line {

    public double slope;
    public double y_int;
    public double x_int;
    public boolean vert;

    public Line(double slope, double y_int){
        this.slope = slope;
        this.y_int = y_int;
        vert = false;
    }

    public Line(double x_int) {
        slope = Double.NaN;
        y_int = Double.NaN;
        vert = true;
        this.x_int = x_int;
    }

    public double getSlope() {
        return slope;
    }

    public double getY_int() {
        return y_int;
    }

    public boolean isVert() {
        return vert;
    }
}



What I have tried:

I suppose it comes down to me not being the best at math. I obviously understand the slope formula but translating to code has proven difficult.

解决方案

Google Search is your friend. This Google Search: java X-intercept of a slope - Google Search[^] found:
* interceptor - find intercept from slope in java - Stack Overflow[^]
* Java Code for Slope Intercept Form[^]
* and more![^]


这篇关于如何使用java查找斜率的X截距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆