Advertisement
kk258966

4/15 物件導向程式設計 練習一

Apr 15th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. class CTriangle
  2. {
  3.         int width;
  4.         int height;
  5.        
  6.         void show_area(){
  7.             System.out.println("area="+(width*height)/2);
  8.         }
  9. }
  10.  
  11. public class B10207081
  12. {
  13.     public static void main(String args[])
  14.     {
  15.         CTriangle tr1,tr2;
  16.         tr1=new CTriangle();
  17.         tr2=new CTriangle();
  18.        
  19.         tr1.width=10;
  20.         tr1.height=5;
  21.        
  22.         tr2.width=20;
  23.         tr2.height=10;
  24.        
  25.         tr1.show_area();
  26.         tr2.show_area();
  27.         System.out.println("B10207081");
  28.     }
  29.    
  30.              
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement