0 java
我需要构建这个程序,找到三角形的缺失面,但我不断收到错误消息.这是我的代码:
import java.util.Scanner;
public class MissingSide {
static java.util.Scanner userInput = new Scanner(System.in);
public static void main(String[] args) {
System.out.print("What is the first side, other than the hypotenuse?");
if (userInput.hasNextInt()) {
int firstsideGiven = userInput.nextInt();
} else {
System.out.println("Enter something acceptable");
}
System.out.println("What is the hypotenuse?");
if (userInput.hasNextInt()) {
int hypotenuseGiven = userInput.nextInt();
} else {
System.out.print("Really?");
}
System.out.print("Your missing side value is: " +
System.out.print((Math.pow(firstsideGiven, 2) - Math.pow(hypotenuseGiven, 2)) + "this");
}
}
Run Code Online (Sandbox Code Playgroud)
它一直告诉我"hypotenuseGiven"和"firstsideGiven"无法解析为变量.这是供个人使用,而不是学校用品.谢谢.
范围hypotenuseGiven和firstsideGiven仅限if() {...}于代码中的语句.
您不能在该范围之外使用它们.如果您希望这样做,请在if() {...}块外面声明它们.