fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. class Box {
  7. double width;
  8. double height;
  9. double depth;
  10.  
  11. double volume() {
  12. return width*height*depth;
  13. }
  14. }
  15. /* Name of the class has to be "Main" only if the class is public. */
  16. class Ideone
  17. {
  18. public static void main (String[] args) throws java.lang.Exception
  19. {
  20. Box mybox1 = new Box();
  21. Box mybox2 = new Box();
  22. double vol;
  23. mybox1.width = 10;
  24. mybox1.height = 5;
  25. mybox1.depth = 6;
  26. mybox2.width = 9;
  27. mybox2.height = 4;
  28. mybox2.depth = 5;
  29. vol = mybox1.volume();
  30. System.out.println("Объем первой коробки равен " + vol);
  31. vol = mybox2.volume();
  32. System.out.println("Объем второй коробки равен " + vol);
  33. }
  34. }
Success #stdin #stdout 0.14s 55728KB
stdin
Standard input is empty
stdout
Объем первой коробки равен 300.0
Объем второй коробки равен 180.0