loops.java सम्पादन

// This program displays a temperature conversion table showing Fahrenheit
// temperatures from 0 to 100, in increments of 10, and the corresponding
// Celsius temperatures using While, For, and Do loops.

import java.util.*;

class loops
{
    private static Scanner input = new Scanner(System.in);
    
    public static void main(String[] args)
    {
        whileLoop();
        forLoop();
        doLoop();
    }

    private static void whileLoop()
    {
        double f;
        double c;
        
        System.out.println("F°    C°");
        f = 0;
        while (f <= 100)
        {
            c = (f - 32) * 5 / 9;
            System.out.println(f + " = " + c);
            f += 10;
        }
    }

    private static void forLoop()
    {
        double f;
        double c;
        
        System.out.println("F°    C°");
        for (f = 0 ; f <= 100 ; f += 10)
        {
            c = (f - 32) * 5 / 9;
            System.out.println(f + " = " + c);
        }
    }

    private static void doLoop()
    {
        double f;
        double c;
        
        System.out.println("F°    C°");
        f = 0;
        do
        {
            c = (f - 32) * 5 / 9;
            System.out.println(f + " = " + c);
            f += 10;
        } while (f <= 100);
    }
}

कोशिश करो सम्पादन

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

यह भी देखें सम्पादन