Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- public class Main {
- public static void main(String[] args) {
- //***1 inch = 2.54cm***\\
- //***1 foot = 12 inches = 30.45cm***\\
- double valueInCentimeters = calcToCentimeters(2, 1);
- if (valueInCentimeters != 0) {
- System.out.println("Podana wartość łokci i stóp wynosi: " + valueInCentimeters + " centrymetrów.");
- }
- System.out.println("");
- double valueInCentimeters2 = calcToCentimeters(24);
- if (valueInCentimeters2 != 0) {
- System.out.println("Podana wartość łokci i stóp wynosi: " + valueInCentimeters2 + " centrymetrów.");
- }
- }
- public static double calcToCentimeters(double foot, double inch) {
- if (foot == 0 || inch == 0) {
- System.out.println("Wartość stopy lub łokcia jest nieprawidłowa. Muszą być większe od 0");
- return -1;
- } else {
- return (inch * 2.54 + foot * 30.45);
- }
- }
- public static double calcToCentimeters(double inch) {
- double foot2, inch2;
- if (inch <= 0) {
- System.out.println("Podana wartość łokci jest nieprawidłowa, musi być większa od 0");
- return 1;
- }
- if (inch > 12) {
- foot2 = inch / 12;
- inch2 = inch % 12;
- System.out.println("W podanej ilości łokci mieści się: " + foot2 + " stóp oraz pozostaje " + inch2 + " łokci");
- return calcToCentimeters(foot2, inch2);
- }
- else {
- return (inch*12);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement