Created
February 15, 2017 09:00
-
-
Save swshan/1af7a78525d15935250d4ac97e8565b0 to your computer and use it in GitHub Desktop.
Java 练习
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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