कंप्यूटर प्रोग्रामिंग/सबरूटीन्स/जावा

विकिविश्वविद्यालय से

subroutines.java[सम्पादन | स्रोत सम्पादित करें]

// This program asks the user for a Fahrenheit temperature,
// converts the given temperature to Celsius,
// and displays the results.

import java.util.*;

class subroutines {
    private static Scanner input = new Scanner(System.in);

    public static void main(String[] args) {
        double f;
        double c;
        
        f = getF();
        c = calculateC(f);
        displayResult(f, c);
    }

    private static double getF() {
        double f;
        
        System.out.println("Enter Fahrenheit temperature:");
        f = input.nextDouble();
        
        return f;
    }

    private static double calculateC(double f) {
        double c;
        
        c = (f - 32) * 5 / 9;
        
        return c;
    }

    private static void displayResult(double f, double c) {
        System.out.println(f + "° Fahrenheit is " + c + "° Celsius");
    }
}

कोशिश करो[सम्पादन | स्रोत सम्पादित करें]

निम्न कोड मुफ्त ऑनलाइन विकास के वातावरण में से एक में ऊपर कॉपी और पेस्ट करो या अपने खुद के जावा कम्पाइलर/इंटरप्रेटर/आईडीई का उपयोग करें।

यह भी देखें[सम्पादन | स्रोत सम्पादित करें]