so I want to know how to make a program that will ask multiple questions and lead to multiple values or other questions to build on.
So I was building a "missing side of right triangle" program. Successful after a couple tries I wondered why not make the program solve obtuse or acute triangles. Well, I could program the law of sines and cosines. The problem is I don't know how. I learned the basics of java through 2-3 videos off youtube. I tried to make an if-else nested inside an if-else statement. But this is my code I tried to build upon:
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)))));
}
}
And now I want to know what to do next, when I attempted to nest everything inside another if statement, it gave me an error I did not understand.
Aucun commentaire:
Enregistrer un commentaire