JAVA类课后练习
1、Pg168--2
package com.hanqi; import java.util.Scanner; public class Rectangle { Rectangle() { //完成初始化 lang=12; wide=10; } //属性 double lang; double wide; //方法 void area() { System.out.println("矩形的面积=" +lang*wide); } public static void main(String[] args) { Rectangle rec=new Rectangle(); System.out.println("矩形的长度=" +rec.lang); System.out.println("矩形的宽度=" +rec.wide); rec.area(); } }
2.计算机完成加减乘除
package com.hanqi; import java.util.Scanner; public class Rectangle { Rectangle() { //完成初始化 lang=12; wide=10; } //属性 double lang; double wide; //方法 void area() { System.out.println("矩形的面积=" +lang*wide); } public static void main(String[] args) { Rectangle rec=new Rectangle(); System.out.println("矩形的长度=" +rec.lang); System.out.println("矩形的宽度=" +rec.wide); rec.area(); } }