Page 62 - CITS - CSA - TP (Volume 2) - Hindi
P. 62

कं  ूटर सॉ वेयर ए ीके शन - CITS




           टा  3: WHILE लूप का उपयोग करके  काउ ्डाउन करना
           import java.util.Scanner;
           public class WhileCountdown {
           public static void main(String[] args) {
                   Scanner scanner = new Scanner(System.in);

           System.out.print(“Enter a starting number for countdown: “);
           int count = scanner.nextInt();
           while (count >= 0) {
           System.out.println(count);
           count--;

                   }
           System.out.println(“Blastoff!”);
           scanner.close();
               }
           }
           आउटपुट:



























           यह  ो ाम उपयोगकता   ारा िनिद   सं ा से शु  होने वाली उलटी िगनती (काउ ्डाउन) बनाने के  िलए while लूप का उपयोग करता है। यह उ ी
           िगनती (काउ ्डाउन) ि ंट करता है और िफर “Blastoff!”  दिश त करता है। जब उ ी िगनती 0 पर प ँचती है।


           टा  4: while लूप का उपयोग करके  फै  ो रयल गणना

           import java.util.Scanner;
           public class WhileFactorial {
           public static void main(String[] args) {

                   Scanner scanner = new Scanner(System.in);
           System.out.print(“Enter a number to calculate its factorial: “);
           int number = scanner.nextInt();

           int factorial = 1;



                                                           48

                                   CITS : IT & ITES - कं  ूटर सॉ वेयर ए ीके शन - अ ास 87
   57   58   59   60   61   62   63   64   65   66   67