Guest User

Untitled

a guest
Jan 24th, 2018
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. package rectangle;
  2.  
  3. public class Rectangle {
  4. int length, width;
  5. }
  6.  
  7. class RectArea {
  8.  
  9. public static void main(String[] args) {
  10.  
  11. int area;
  12.  
  13. Rectangle rect = new Rectangle();
  14. rect.length = 14;
  15. rect.width = 13;
  16.  
  17. area = rect.length * rect.width;
  18. }
  19. }
  20.  
  21. area = rect.area;
  22.  
  23. public class Rectangle {
  24.  
  25. int length, width, area;
  26.  
  27. void getData(int x, int y) {
  28. length = x;
  29. width = y;
  30. area = length * width;
  31. }
  32. }
  33.  
  34. int length, width, area;
  35.  
  36. void getData(int x, int y)
  37. {
  38. length=x;
  39. width=y;
  40. }
  41.  
  42. int rectArea()
  43. {
  44. area=length*width;
  45. return area;
  46.  
  47. }
  48.  
  49. }
  50. class RectArea{
  51.  
  52. public static void main(String[] args) {
  53.  
  54. int area1, area2;
  55.  
  56. Rectangle rect1 =new Rectangle();
  57.  
  58. Rectangle rect2 =new Rectangle();
  59.  
  60. rect1.length=14;
  61. rect1.width=13;
  62. area1=rect1.length*rect1.width;
  63. rect2.getData(13,14);
  64. area2=rect2.rectArea();
  65.  
  66. System.out.println("Area1="+ area1);
  67. System.out.println("Area1="+ area2);
  68. System.out.println("Area1="+ rect2.area);
  69. }
  70.  
  71. }
Add Comment
Please, Sign In to add comment