fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.math.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. private static final int SCALE = 2;
  12.  
  13. public static void main(String[] args) {
  14. new Ideone().run();
  15. }
  16.  
  17. private void run() {
  18. BigDecimal hundredLbs = new BigDecimal(100.00);
  19. BigDecimal hundredInches = new BigDecimal(100.00);
  20.  
  21. System.out.println(hundredLbs + " pounds is " + poundsToKilos(hundredLbs) + " kilos and converts back to " + kilosToPounds(poundsToKilos(hundredLbs)) + " pounds.");
  22. System.out.println(hundredInches + " inches is " + inchesToMeters(hundredInches) + " meters and converts back to " + metersToInches(inchesToMeters(hundredInches)) + " inches.");
  23. }
  24.  
  25. private BigDecimal metersToInches(BigDecimal meters) {
  26. return meters.multiply(new BigDecimal(39.37)).setScale(SCALE, BigDecimal.ROUND_HALF_UP);
  27. }
  28.  
  29. private BigDecimal inchesToMeters(BigDecimal inches) {
  30. return inches.multiply(new BigDecimal(0.0254)).setScale(SCALE, BigDecimal.ROUND_HALF_UP);
  31. }
  32.  
  33. private BigDecimal kilosToPounds(BigDecimal kilos) {
  34. return kilos.multiply(new BigDecimal(2.2046226218)).setScale(SCALE, BigDecimal.ROUND_HALF_UP);
  35. }
  36.  
  37. private BigDecimal poundsToKilos(BigDecimal pounds) {
  38. return pounds.multiply(new BigDecimal(0.453592370010035)).setScale(SCALE, BigDecimal.ROUND_HALF_UP);
  39. }
  40. }
Success #stdin #stdout 0.06s 28264KB
stdin
Standard input is empty
stdout
100 pounds is 45.36 kilos and converts back to 100.00 pounds.
100 inches is 2.54 meters and converts back to 100.00 inches.