我有一个任务来编写一个程序,该程序使用我必须编写的方法triangleType,以便从用户那里获取三个int输入并输出三角形类型。在该方法中,我首先需要按升序对整数进行排序,以便我需要使用的比较能够正常工作。我知道我在代码中正确地完成了排序部分,因为我在开始尝试确定三角形类型之前就对其进行了测试。我需要使用这些比较来找到三角形类型:“如果A + B<= C,那么边不代表有效的三角形。如果 A = C(所有边的长度必须相同),则三角形为等边。如果 A = B 或 B = C,则三角形为等腰;否则三角形是SCALENE“由于某些原因,我在triangleType方法末尾的if语句无法正常工作,并且我得到了各种输出,包括”无效三角形“以及其他输出,无论我输入的整数如何。
package trianglemethod;
import javax.swing.JOptionPane;
public class TriangleMethod
{
public static void main(String[] args)
{
String wordaA, wordbB, wordcC, answer;
do
{
System.out.println("Please enter all 3 side lengths of the triangle in any order.");
wordaA = JOptionPane.showInputDialog("Enter side 1:");
wordbB = JOptionPane.showInputDialog("Enter side 2:");
wordcC = JOptionPane.showInputDialog("Enter side 3:");
int aA = Integer.parseInt(wordaA);
int bB = Integer.parseInt(wordbB);
int cC = Integer.parseInt(wordcC);
triangleType(aA,bB,cC);
System.out.println("Would you like to enter another triangle?");
answer = JOptionPane.showInputDialog("Would you like to enter another triangle?");
} while (answer.equalsIgnoreCase("yes"));
}
static void triangleType(int aA, int bB, int cC) {
int a=0, b=0, c=0;
if (aA > bB && aA > cC)
{
if (bB > cC)
{
a = cC;
b = bB;
c = aA;
}
else if (cC > bB)
{
a = bB;
b = cC;
c = aA;
}
}
if (bB > aA && bB > cC)
{
if (aA > cC)
{
a = cC;
b = aA;
c = bB;
}
else if (cC > aA)
{
a = aA;
b = cC;
c = bB;
}
}
慕的地6264312
眼眸繁星
繁星coding
烙印99
随时随地看视频慕课网APP
相关分类