2013年3月24日

向一个方法的基本数据类型参数传值

摘要: class Tom{void f(int x,double y){x=x+1;y=y+1;System.out.printf("x y : %d,%3.2f\n",x,y);}}public class Example4_7{public static void main(String args[]){int x=10;double y=12.58;Tom cat=new Tom();cat.f(x,y);System.out.printf("main x y: %d,%3.2f\n",x,y);}} 阅读全文

posted @ 2013-03-24 17:23 agony· 阅读(148) 评论(0) 推荐(0)

通过类名调用类方法

摘要: class Computer{double x,y;static double max(double a,double b){return a>b?a:b;}}class Example4_6{public static void main(String args[]){double max=Computer.max(12,45);System.out.println(max);}} 阅读全文

posted @ 2013-03-24 16:44 agony· 阅读(372) 评论(0) 推荐(0)

常量的用法

摘要: class Tom{final int MAX=100;static final int MIN=20;}public class Example4_5{public static void main(String args[]){System.out.println(Tom.MIN);Tom cat=new Tom();int x=0;x=Tom.MIN+cat.MAX;System.out.println(x);}} 阅读全文

posted @ 2013-03-24 16:37 agony· 阅读(172) 评论(0) 推荐(0)

两个lader对象共享bottom

摘要: class Lader{ double above,height; static double bottom; void setAbove(double a){ above=a;} void setBottom(double b){ bottom=b; } double getAbove(){ return above; } double getBottom(){return bottom;}}class Example4_4{ public static void main(String args[]){ Lader.bottom=60; Lader laderOne,laderTwo;.. 阅读全文

posted @ 2013-03-24 16:29 agony· 阅读(158) 评论(0) 推荐(0)

使用lader类创建两个对象

摘要: class Lader{double above,bottom,height;Lader(){}Lader(double a,double b,double h){above=a;bottom=b;height=h;}public void setAbove(double a){above=a;}public void setBottom(double b){bottom=b;}public void setHeight(double h){height=h;}double computerArea(){return(above+bottom)*height/2.0;}}public clas 阅读全文

posted @ 2013-03-24 15:40 agony· 阅读(264) 评论(0) 推荐(0)

输出圆的面积

摘要: public class ComputerCircleArea{public static void main(String args[]){double radius;double area;radius=163.16;area=3.14*radius*radius;System.out.printf("banjingshi%5.3fdeyuandemianji: \n%5.3f\n",radius,area);}} 阅读全文

posted @ 2013-03-24 14:55 agony· 阅读(179) 评论(0) 推荐(0)

导航