请java大神帮忙写出一下程序的子程序.- -|| 越快越好 谢谢了.
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/18 14:16:20
请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"));
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"));
这个程序据我看是判断三角形的形状的,但是缺了第一步——判断三个边能不能构成三角形.
package test;
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+" ";
}
}
package test;
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+" ";
}
}
请java大神帮忙写出一下程序的子程序.- -|| 越快越好 谢谢了.
请帮忙一下写出了春天的色彩谢谢!
急!求大神帮忙看看做错了没,如果有错的请帮忙改一下.谢谢!
求大神帮忙写一个java程序
求大神帮忙编下这几个JAVA程序
请大神帮忙翻译一下,谢谢了,关于英语名人名言的翻译
急!简便计算,求大神帮忙看看做错了没,如果有错的请帮忙改一下.谢谢!
Rice写出同类的单词谢谢了,大神帮忙啊
求大神用eclipse java 编写一个程序,全分送上,急求,谢谢了
请大家帮忙翻译一下下面这段英语.谢谢了,大神帮忙啊
请各位英语大神帮忙修改一下以下的英文文章,本人英文不好,有很多语病,先谢谢了。
java如何获取汉字的拼音字母?请帮忙讲一下实现原理,最好能贴出java源码