请java大神帮忙写出一下程序的子程序.- -|| 越快越好 谢谢了.import java.util.Scanner;public class Assignment5 { // public static void main (String[] args) { Scanner console = new Scanner(System.in); int num1, num2, nu
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/16 18:49:48
请java大神帮忙写出一下程序的子程序.- -|| 越快越好 谢谢了.import java.util.Scanner;public class Assignment5 { // public static void main (String[] args) { Scanner console = new Scanner(System.in); int num1, num2, nu
请java大神帮忙写出一下程序的子程序.- -|| 越快越好 谢谢了.
import java.util.Scanner;
public class Assignment5 {
//
public static void main (String[] args) {
Scanner console = new Scanner(System.in);
int num1, num2, num3;
String another;
do
{
System.out.println("Enter the sides of the triangle: ");
num1 = console.nextInt();
num2 = console.nextInt();
num3 = console.nextInt();
Triangle myTriangle = new Triangle (num1, num2, num3);
System.out.println(myTriangle.toString() + " triangle:");
//check the isosceles
if (myTriangle.is_isosceles())
System.out.println("\tIt is isosceles");
else
System.out.println("\tIt is not isosceles");
//check the equilateral
if (myTriangle.is_equilateral())
System.out.println("\tIt is equilateral");
else
System.out.println("\tIt is not a equilateral");
//check the scalene
if (myTriangle.is_scalene())
System.out.println("\tIt is scalene");
else
System.out.println("\tIt is not scalene");
System.out.println();
System.out.print("Check another Triangle (y/n)? ");
another = console.next();
} while (another.equalsIgnoreCase("y"));
请java大神帮忙写出一下程序的子程序.- -|| 越快越好 谢谢了.import java.util.Scanner;public class Assignment5 { // public static void main (String[] args) { Scanner console = new Scanner(System.in); int num1, num2, nu
这个程序据我看是判断三角形的形状的,但是缺了第一步——判断三个边能不能构成三角形.
import java.util.Scanner;
public class Assignment5 {
//
public static void main (String[] args) {
Scanner console = new Scanner(System.in);
int num1, num2, num3;
String another;
do
{
System.out.println("Enter the sides of the triangle: ");
num1 = console.nextInt();
num2 = console.nextInt();
num3 = console.nextInt();
Triangle myTriangle = new Triangle (num1, num2, num3);
System.out.println(myTriangle.toString() + " triangle:");
if(myTriangle.is_Triangle()){
System.out.println("\tcan construct the triangle");
//check the isosceles
if (myTriangle.is_isosceles())
System.out.println("\tIt is isosceles");
else
System.out.println("\tIt is not isosceles");
//check the equilateral
if (myTriangle.is_equilateral())
System.out.println("\tIt is equilateral");
else
System.out.println("\tIt is not a equilateral");
//check the scalene
if (myTriangle.is_scalene())
System.out.println("\tIt is scalene");
else
System.out.println("\tIt is not scalene");
}
else
{
System.out.println("\tcan not construct the triangle");
}
System.out.println();
System.out.print("Check another Triangle (y/n)? ");
another = console.next();
} while (another.equalsIgnoreCase("y"));
}
}
Triangle.java
package test;
public class Triangle {
private int line1;
private int line2;
private int line3;
public Triangle(int num1, int num2, int num3) {
// TODO Auto-generated constructor stub
line1 = num1;
line2 = num2;
line3 = num3;
}
public boolean is_Triangle()
{
if((line1 + line2 > line3) && (line1 + line3 > line2) && (line3 + line2 > line1))
{
return true;
}
return false;
}
public boolean is_isosceles() {
// TODO Auto-generated method stub
if((line1 == line2) || (line1 == line3) || (line2 == line3))
{
return true;
}
return false;
}
public boolean is_equilateral() {
// TODO Auto-generated method stub
if((line1 == line2) && (line2 == line3))
{
return true;
}
return false;
}
public boolean is_scalene() {
// TODO Auto-generated method stub
if((line1 != line2) && (line2 != line3) && (line1 != line3))
{
return true;
}
return false;
}
public String toString()
{
return "Triangle which lines is "+line1+" "+line2+" "+line3+" ";
}
}