Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. //***1 inch = 2.54cm***\\
  8. //***1 foot = 12 inches = 30.45cm***\\
  9.  
  10. double valueInCentimeters = calcToCentimeters(2, 1);
  11. if (valueInCentimeters != 0) {
  12. System.out.println("Podana wartość łokci i stóp wynosi: " + valueInCentimeters + " centrymetrów.");
  13. }
  14. System.out.println("");
  15.  
  16. double valueInCentimeters2 = calcToCentimeters(24);
  17. if (valueInCentimeters2 != 0) {
  18. System.out.println("Podana wartość łokci i stóp wynosi: " + valueInCentimeters2 + " centrymetrów.");
  19. }
  20.  
  21.  
  22. }
  23.  
  24. public static double calcToCentimeters(double foot, double inch) {
  25.  
  26.  
  27. if (foot == 0 || inch == 0) {
  28. System.out.println("Wartość stopy lub łokcia jest nieprawidłowa. Muszą być większe od 0");
  29. return -1;
  30. } else {
  31. return (inch * 2.54 + foot * 30.45);
  32. }
  33. }
  34.  
  35.  
  36.  
  37.  
  38. public static double calcToCentimeters(double inch) {
  39. double foot2, inch2;
  40. if (inch <= 0) {
  41. System.out.println("Podana wartość łokci jest nieprawidłowa, musi być większa od 0");
  42. return 1;
  43. }
  44.  
  45. if (inch > 12) {
  46. foot2 = inch / 12;
  47. inch2 = inch % 12;
  48. System.out.println("W podanej ilości łokci mieści się: " + foot2 + " stóp oraz pozostaje " + inch2 + " łokci");
  49. return calcToCentimeters(foot2, inch2);
  50. }
  51.  
  52. else {
  53. return (inch*12);
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement