這就是我目前爲止的內容。它編譯和運行,但直到用戶放在每個長度的一側。信息輸入後,程序應告訴用戶它是什麼三角形,但不是。我正在編寫一個代碼,通過獲取用戶各邊的長度來確定三角形的類型(等邊,斜角,等腰三角形)。
import java.util.Scanner; //declare scanner
public class SideClassification {
public static void main(String [] args)
{
Scanner input = new Scanner (System.in); //declare scanner
//declare sides of triangle
int sideA = 0;
int sideB = 0;
int sideC = 0;
System.out.print ("Enter the length of side A: "); //ask user for length of side A
sideA = input.nextInt();
System.out.print ("Enter the length of side B: "); //ask user for length of side B
sideB = input.nextInt();
System.out.print ("Enter the length of side C: "); //ask user for lenght of side C
sideC = input.nextInt();
}
public static boolean isEqualateral (int sideA, int sideB, int sideC) //if statement for equalateral triangle
{
if ((sideA == sideB) && (sideB == sideC))
{
return true;
}
else
{
return false;
}
}
public static boolean isIsoceles (int sideA, int sideB, int sideC) //if statement for isoceles triangle
{
if((sideA == sideB) || (sideA == sideC) || (sideB == sideC))
{
return true;
}
else
{
return false;
}
}
public static boolean isScalene (int sideA, int sideB, int sideC) //if statement for scalene triangle
{
if((sideA != sideB) && (sideA != sideC) && (sideB != sideC))
{
return true;
}
else
{
return false;
}
}
}
你需要調用函數'isEqualateral','isIsoceles'和'isScalene'。 –