java子程序_请java大神帮忙写出一下程序的子程序.- -|| 越快越好 谢谢了.

共回答了17个问题采纳率:82.4%

这个程序据我看是判断三角形的形状的,但是缺了第一步——判断三个边能不能构成三角形.

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 thetriangle");

//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 thetriangle");

}

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+" ";

}

}

1年前

7

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值