Hey all, I've got an assignment in my compsci class to make a program where the user inputs values for a, b, and c, and the program identifies it as either a right triangle or a not a right triangle.
As part of the assignment, I have to incorporate some if/else statements (where I decided to inject a bit of fun), but that is where I begin seeing some errors... I think I may have failed to import a class, or perhaps I should be using "String" instead of "Boolean"? I've tried quite a few things, but my efforts thus far remain fruitless.
So, check out my code and see if you can find something that I haven't? TIA :D
import java.util.Scanner;
import java.lang.Math;
import java.lang.Boolean;
public class Triangle {
public static void main (String [] args){
Scanner input = new Scanner(System.in);
double a; //first leg of triangle
double b; //second leg
double c; //hypotenuse
Boolean x; //
System.out.println("Measure the first leg of triangle!");
a = input.nextDouble();
System.out.println("Measure the second leg of triangle!");
b = input.nextDouble();
System.out.println("Measure the hypotenuse of triangle!");
c = input.nextDouble();
System.out.print("Do you wish to use a Pokeball? Y/N");
x = input.nextString();
if(x = "Y"){
System.out.println("Trainer threw a Pokeball!");
System.out.println("...");
System.out.println("...");
System.out.println("...");
if(a*a+b*b == c*c){
System.out.println("Congratulations, you have caught a Right Triangle!");
}else{
System.out.println("Oh! The Pokemon could not be caught!");
}}if(x = "N"){
System.out.println("Too bad! Trainer threw a Pokeball anyway!");
System.out.println("...");
System.out.println("...");
System.out.println("...");
if(a*a+b*b == c*c){
System.out.println("Congratulations, you have caught a Right Triangle!");
}else{
System.out.println("Oh! The Pokemon could not be caught!");
}}else{
System.out.println("FATAL ERROR: INCORRECT INPUT. YOU JUST LOST THE GAME. RESET APPLICATION TO TRY AGAIN.");
}
}
}
Question
Labot2001
Hey all, I've got an assignment in my compsci class to make a program where the user inputs values for a, b, and c, and the program identifies it as either a right triangle or a not a right triangle.
As part of the assignment, I have to incorporate some if/else statements (where I decided to inject a bit of fun), but that is where I begin seeing some errors... I think I may have failed to import a class, or perhaps I should be using "String" instead of "Boolean"? I've tried quite a few things, but my efforts thus far remain fruitless.
So, check out my code and see if you can find something that I haven't? TIA :D
import java.util.Scanner; import java.lang.Math; import java.lang.Boolean; public class Triangle { public static void main (String [] args){ Scanner input = new Scanner(System.in); double a; //first leg of triangle double b; //second leg double c; //hypotenuse Boolean x; // System.out.println("Measure the first leg of triangle!"); a = input.nextDouble(); System.out.println("Measure the second leg of triangle!"); b = input.nextDouble(); System.out.println("Measure the hypotenuse of triangle!"); c = input.nextDouble(); System.out.print("Do you wish to use a Pokeball? Y/N"); x = input.nextString(); if(x = "Y"){ System.out.println("Trainer threw a Pokeball!"); System.out.println("..."); System.out.println("..."); System.out.println("..."); if(a*a+b*b == c*c){ System.out.println("Congratulations, you have caught a Right Triangle!"); }else{ System.out.println("Oh! The Pokemon could not be caught!"); }}if(x = "N"){ System.out.println("Too bad! Trainer threw a Pokeball anyway!"); System.out.println("..."); System.out.println("..."); System.out.println("..."); if(a*a+b*b == c*c){ System.out.println("Congratulations, you have caught a Right Triangle!"); }else{ System.out.println("Oh! The Pokemon could not be caught!"); }}else{ System.out.println("FATAL ERROR: INCORRECT INPUT. YOU JUST LOST THE GAME. RESET APPLICATION TO TRY AGAIN."); } } }Link to comment
Share on other sites
4 answers to this question
Recommended Posts