• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
wangchunmei
博客园 首页 新随笔 联系 订阅 订阅 管理
上一页 1 2 3 4 下一页

2013年3月20日

构造方法,类创建对象的调用,创建对象,为对象分配成员变量。。(Example4_2)
摘要: 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 computeArea(){return (above+bottom)*height/2.0;}}public cla 阅读全文
posted @ 2013-03-20 22:26 wangchunmei 阅读(172) 评论(0) 推荐(0)
 
 

2013年3月19日

计算圆的面积(Circle类创建对象)
摘要: public class ComputerCircleArea{public static void main(String arg[]){double radius;double area;radius=163.16;area=3.14*radius*radius;System.out.printf("%5.3f:\n%5.3f\n",radius,area);}}class Circle{double radius;double getArea(){double area=3.14*radius*radius;return area;}}public class Exa 阅读全文
posted @ 2013-03-19 22:16 wangchunmei 阅读(781) 评论(0) 推荐(0)
 
Java中类体的构成
摘要: class 类名{ 类体的内容 } /\ (成员变量和 方法){定义类的成员变量时可以赋初值,注意:对成员变量的操作只能放在方法中}例如::class A{ /\ int a=9; (构造方法和对象调用) float b=12.6f;| void f(){a=12;b=12.56f}(构造方法,它的名字必须与它的所在类的名字完全相同,而且没有返回型) }类所创建对象的调用首先要创建对象:类创建对象::(创建对象就是只为它分配成员变量)1:对象声明(类的名字 对象名字)2:为声明的对象分配成员变量(用new运算符和类的构造方法)RectrectangleOne;rectangle=new Rec 阅读全文
posted @ 2013-03-19 22:07 wangchunmei 阅读(714) 评论(0) 推荐(0)
 
 

2013年3月16日

跳转语句
摘要: public class Example3_7{public static void main(String args[]){int sum=0,i=0,max=8888,number=7;while(true){i++;sum=sum+i;if(sum>=max)break;}System.out.println("1+2+...n<"+max+"的最大整数n:"+(i-1));for(i=1,max=200,sum=0;i<=max;i++){if(i%number!=0){continue;}sum=sum+i;}System.o 阅读全文
posted @ 2013-03-16 22:03 wangchunmei 阅读(192) 评论(0) 推荐(0)
 
循环语句
摘要: public class Example3_5{public static void main(String args[]){double sum=0,item=1;int i=1;while(i<=1000){sum=sum+item;i++;item=item*(1.0/i);}sum=sum+1;System.out.println("e="+sum);sum=0;i=1;item=1;do{sum=sum+item;i++;item=item*(1.0/i);}while(i<=1000);sum=sum+1;System.out.println(&qu 阅读全文
posted @ 2013-03-16 21:24 wangchunmei 阅读(132) 评论(0) 推荐(0)
 
Example3_4(switch语句)
摘要: import java.util.*;public class Example3_4{public static void main(String arg[]){Scanner reader =new Scanner(System.in);System.out.println("输入一个月份:");int n=reader.nextInt();switch(n){case 1:case 2:case 3:System.out.printf("%d月属于第一季度",n);break;case 4:case 5:case 6:System.out.print 阅读全文
posted @ 2013-03-16 20:49 wangchunmei 阅读(166) 评论(0) 推荐(0)
 
Example3_3(if-else语句)
摘要: import java.util.*;public class Example3_3{public static void main(String args[]){Scanner reader=new Scanner(System.in);double a=0,b=0,c=0;System.out.print("输入边a:");a=reader.nextDouble();System.out.print("输入边b:");b=reader.nextDouble();System.out.print("输入边c:");c=reader. 阅读全文
posted @ 2013-03-16 20:33 wangchunmei 阅读(314) 评论(0) 推荐(0)
 
 

2013年3月15日

Example3_2(异或运算)
摘要: public class Example3_2{public static void main(String arg[]){char a[]={'金','木','水','火','土'};char secret='z';for(int i=0;i<a.length;i++){a[i]=(char)(a[i]^secret);}System.out.printf("密文: \n");for(int i=0;i<a.length;i++){System.out.printf 阅读全文
posted @ 2013-03-15 21:16 wangchunmei 阅读(271) 评论(0) 推荐(0)
 
Example3_1(移位运算)
摘要: import java.util.*;public class Example3_1{public static void main(String arg[]){Scanner reader=new Scanner(System.in);System.out.println("输入待移位的int整型数:");int x=reader.nextInt();System.out.println("输入移位量:");int n=reader.nextInt();System.out.println("左移位的结果:"+(x<<n 阅读全文
posted @ 2013-03-15 20:40 wangchunmei 阅读(197) 评论(0) 推荐(0)
 
Example2_5(数组的引用)
摘要: public class Example2_5{public static void main(String arg[]){int [] a={1,2,3};int [] b={10,11};System.out.println("数组a的引用:"+a);System.out.println("数组b的引用:"+b);System.out.printf("b[0]=%-3db[1]=%-3d\n",b[0],b[1]);b=a;System.out.println("数组a的引用:"+a);System.out.p 阅读全文
posted @ 2013-03-15 20:17 wangchunmei 阅读(160) 评论(0) 推荐(0)
 
 
上一页 1 2 3 4 下一页

公告


博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3