Prompt for three (3) nonzero integers and determine and print if they could be sides of a right-angled triangle (Hint: any two sides are equal)
import java.util.Scanner;
public class printTriangle {
public static String drawTriangle(int n){
String s = "";
for (int i = 1; i <= n; i++){
for (int j = 1; j <= i; j++)
s += "*";
s += "\n";
}
return s;
}
public static void main(String[] args) {
System.out.println("Please input 1st side:");
String first = (new Scanner(System.in)).nextLine();
System.out.println("Please input 2nd side:");
String second = (new Scanner(System.in)).nextLine();
System.out.println("Please input 3rd side:");
String third = (new Scanner(System.in)).nextLine();
int firstSide = Integer.valueOf(first);
int secondSide = Integer.valueOf(second);
int thirdSide = Integer.valueOf(third);
if(firstSide==secondSide && secondSide==thirdSide){
String output = "";
output += drawTriangle(firstSide);
System.out.println("Could be");
System.out.println(output);
}
else{
System.out.println("Could NOT be");
}
}
}