0
所以我想知道如何製作一個程序,該程序會提出多個問題,並導致多個值或其他問題的基礎上。延伸下面的程序爲急性和鈍角三角形|使用正弦cos函數
所以我建立了一個「直角三角形缺失的一面」程序。在一對夫婦嘗試後成功我想知道爲什麼不讓程序解決鈍角或銳角三角形。那麼,我可以編制正弦和餘弦的規律。問題是我不知道如何。我通過關於YouTube的2-3個視頻瞭解了Java的基礎知識。我試圖在if-else語句中嵌套一個if-else。但是,這是我的代碼我試圖建立在:
import java.util.*;
import java.lang.Math;
public class MissingSide {
static java.util.Scanner userInput = new Scanner(System.in);
public static void main(String[] args){
int firstSideGiven = 0;
int hypotenuseGiven = 0;
Scanner userInput = new Scanner(System.in);
System.out.println("Are you trying to figure out a missing side given the hypotenuse and another side?");
System.out.println("Then this is the place :)");
System.out.print("What is the value of the first side, other than the hypotenuse?");
if (userInput.hasNextInt()) {
firstSideGiven = userInput.nextInt();
}else{
System.out.println("Give me somthing else to work with!");
}
System.out.println("What is your hypotenuse?");
if (userInput.hasNextInt()){
hypotenuseGiven = userInput.nextInt();
}else{
System.out.print("Wait, I want you to think about what you are doing with your life.");
}
System.out.println("Your missing side is: " + (Math.sqrt((Math.pow(hypotenuseGiven, 2)-Math.pow(firstSideGiven, 2)))));
}
}
,現在我想知道下一步該怎麼做,當我試圖窩在心裏的另一個if語句,它給了我一個錯誤,我不明白。
如果你向我們展示了嘗試和錯誤 – Li357
如果你正在製作菜單驅動程序,開關盒可以更好地工作 –
如果用戶沒有提供整數,那麼wouldn'你想要回去再試一次還是退出程序?第一個需要一個循環。顯而易見的退出方式是將main方法的其餘行放入if語句中 - 所以是的,如果其他情況發生,您將會有其他內容。 –