Skip to content

Instantly share code, notes, and snippets.

@swshan
Created February 15, 2017 09:00
Show Gist options
  • Save swshan/1af7a78525d15935250d4ac97e8565b0 to your computer and use it in GitHub Desktop.
Save swshan/1af7a78525d15935250d4ac97e8565b0 to your computer and use it in GitHub Desktop.
Java 练习
package Rectangle;
class myRectangle {
double width = 1.0;
double height = 1.0;
myRectangle() {
}
myRectangle(double newWidth, double newHeight) {
width = newWidth;
height = newHeight;
}
double getArea() {
return width * height;
}
double getPerimeter() {
return width * height;
}
}
public class Rectangle{
public static void main(String[] args) {
myRectangle r1 = new myRectangle();
r1.width = 4;
r1.height = 40;
System.out.println(r1.getArea());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment