gpt4 book ai didi

java - "if"语句的多重含义

转载 作者:行者123 更新时间:2023-12-01 16:37:11 25 4
gpt4 key购买 nike

我正在尝试实现如果斜率一为正(大于零)并且斜率1为正乘以-1

'线程“main”java.lang.Error中出现异常: Unresolved 编译问题:标记“;”上的语法错误,。预期的lope1 无法解析或不是字段

在 LinearSlopeFinder.main(LinearSlopeFinder.java:25);

我尝试过使用“,”代替,但没有骰子

import java.util.Scanner;

public class LinearSlopeFinder {
public static void main(String[]args){
double x1, y1, x2, y2, n1, equation, constant = 0 ;
double slope, slope1, slopeAns;
Scanner myScanner = new Scanner(System.in);

System.out.print(" What is the first set of cordinants? example: x,y ... ");
String coordinate1 = myScanner.nextLine();
String coordinates[] = coordinate1.split(",");
x1 = Integer.parseInt(coordinates[0]);
y1 = Integer.parseInt(coordinates[1]);

System.out.print(" What is the second set of cordinants? example: x,y ... ");
String coordinate2 = myScanner.nextLine();
String coordinates1[] = coordinate2.split(",");
x2 = Integer.parseInt(coordinates1[0]);
y2 = Integer.parseInt(coordinates1[1]);

//remember it is Rise over Run Y's over X's
slope = (y1-y2);
slope1= (x1-x2);
slopeAns= slope / slope1 ;
//below is the part that is not compiling but I am trying to insert
if ( slope > 0 ; slope1 > 0 ){
slope = slope * -1;
slope1 = slope1 * -1;
}

最佳答案

您想要使用 && 运算符来表示“and”。我建议您阅读operators section Java 教程(其余部分也很有值(value))。

关于java - "if"语句的多重含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7857634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com