| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1823 人关注过本帖
标题:写一个java的程序
只看楼主 加入收藏
米团
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2016-4-6
结帖率:33.33%
收藏
已结贴  问题点数:20 回复次数:3 
写一个java的程序
   1.定义一个三角形类Triangle,成员属性包括三条边,能否构成三角形的标志,成员方法包括构造方法,修改三条边,计算面积
2.写一个测,类,测试自定义三角形类Triangle是否正确。写一个JAVA程序,谢谢啦
搜索更多相关主题的帖子: JAVA程序 三角形 java 
2016-05-25 13:29
dkplus
Rank: 2
等 级:论坛游民
帖 子:12
专家分:45
注 册:2016-5-17
收藏
得分:10 
这是作业吗?

linux教程,微信公众号dkplus
2016-05-26 17:34
郑家兴
Rank: 2
来 自:山东省临沂市
等 级:论坛游民
威 望:4
帖 子:22
专家分:66
注 册:2016-2-29
收藏
得分:0 
import java.util.*;
public class Triangle {
    public static void main(String[] args) {
        // TODO Auto-generated method stu
        Scanner in=new Scanner(System.in);
        System.out.println("The first length of a side:");
        int a=in.nextInt();
        System.out.println("The second length of a side:");
        int b=in.nextInt();
        System.out.println("The thirst length of a side:");
        int c=in.nextInt();
        Trian test=new Trian(a,b,c);
        while(true){
            test.judge();
            System.out.println("Please input the index of side and length:");
            int d=in.nextInt();
            int e=in.nextInt();
            test.change(d, e);
        }
    }
}
class Trian{
    int a;
    int b;
    int c;
    public Trian(int a,int b,int c){
        this.a=a;
        this.b=b;
        this.c=c;
    }
    public void judge (){
        if(a+b>c){
            if(b+c>a){
                if(a+c>b){
                    System.out.println("This can form a trigon!");
                    int p=(a+b+c)/2;
                    int t=p*(p-a)*(p-b)*(p-c);
                    double s=Math.sqrt(t);
                    System.out.println("This trigon area is "+s);
                }
                else{
                    System.out.println("This can't form a trigon!");
                }
            }
            else{
                System.out.println("This can't form a trigon!");
            }
        }
        else{
            System.out.println("This can't form a trigon!");
        }
    }
    public void change(int d,int e){
        switch(d){
        case 1:
            this.a=e;
            break;
        case 2:
            this.b=e;
            break;
        case 3:
            this.c=e;
            break;
        }
    }
}

菜鸟要成长
2016-05-28 11:59
郑家兴
Rank: 2
来 自:山东省临沂市
等 级:论坛游民
威 望:4
帖 子:22
专家分:66
注 册:2016-2-29
收藏
得分:0 
我也学的时间不长,很简陋的

菜鸟要成长
2016-05-28 12:00
快速回复:写一个java的程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016725 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved