| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 301 人关注过本帖
标题:[求助]我的这个程序不出结果
取消只看楼主 加入收藏
北恩
Rank: 1
来 自:西安
等 级:新手上路
帖 子:16
专家分:0
注 册:2007-7-8
收藏
 问题点数:0 回复次数:4 
[求助]我的这个程序不出结果
大家帮帮我啊
这个程序不出 结果
有异常
可是我不知道怎么改
一个就是求长方形的面积什么的
的二个是继承
然后重写父类的某些方法
搜索更多相关主题的帖子: 结果 
2007-10-30 11:28
北恩
Rank: 1
来 自:西安
等 级:新手上路
帖 子:16
专家分:0
注 册:2007-7-8
收藏
得分:0 

public class MyRectangle {
private int rxUp,ryUp,lxUp,lyUp;
int width;
int height;
int area1;

public MyRectangle(int rxUp,int ryUp,int lxUp,int lyUp){
this.lxUp=lxUp;
this.lyUp=lyUp;
this.rxUp=rxUp;
this.ryUp=ryUp;
}//构造方法

public int getW(){
width=lyUp-ryUp;
return width;
}

public int getH(){
height=rxUp-lxUp;
return height;
}

public int area(int width,int height){
this.getH();
this.getW();
area1=height*width;
return area1;
}

public String toString(){
return "宽:"+width+" 长:"+height+" 面积:"+area1;
}

/*public int getrxUp(){
return rxUp;
}
public int getlxUp(){
return lxUp;
}
public int getryUp(){
return ryUp;
}
public int getlyUp(){
return lyUp;
}*/

public static void main(String args[]){
MyRectangle a= new MyRectangle(20,5,10,20);
a.area(a.getH(),a.getW());
System.out.println(a.toString());
}
}

public class MyCube extends MyRectangle{
MyRectangle mian;
int d;
long areac;
long vol;

public MyCube(int rxUp,int ryUp,int lxUp,int lyUp,int f){
super(rxUp,ryUp,lxUp,lyUp);
this.d=f;
}

public long volume(){
vol=mian.width*mian.height*d;
return vol;
}

public long cubearea(){
areac=2*(super.area(mian.width,mian.height)+super.area(mian.width,d)+super.area(d,mian.height));
return areac;
}

public static void main(String args[]){
try{
MyCube mc=new MyCube(20,5,10,20,6);
//mc.getH();
//mc.getW();
System.out.println("立方体的表面积:"+mc.cubearea());
System.out.println("立方体的体积:"+mc.volume());
}catch(NullPointerException ex){
//System.out.println("the error is"+ex);
//ex.printStackTrace();
System.out.println("the error is:"+ex.getMessage());
}
}
}


2007-10-30 12:22
北恩
Rank: 1
来 自:西安
等 级:新手上路
帖 子:16
专家分:0
注 册:2007-7-8
收藏
得分:0 

我帖了代码了啊
怎么还是没动静呢???
帮帮我啊
很向知道为什么啊

2007-11-02 20:51
北恩
Rank: 1
来 自:西安
等 级:新手上路
帖 子:16
专家分:0
注 册:2007-7-8
收藏
得分:0 
回复:(酷儿)一个JAVA里不能有2个PUBLIC类

这个我知道
只是在这里我把他们放在一起
在我的电脑上运行的时候
是存在了两个文件
不过
还是谢谢啦

2007-11-08 13:56
北恩
Rank: 1
来 自:西安
等 级:新手上路
帖 子:16
专家分:0
注 册:2007-7-8
收藏
得分:0 
回复:(Donet)你有两个程序入口这是不行的
什么叫做两个程序入口啊
能不能详细点说呢
谢谢
2007-11-08 13:57
快速回复:[求助]我的这个程序不出结果
数据加载中...
 
   



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

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