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

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




           अ ास 89: Break और Continue कीवड  का उपयोग कर  (Use the Break and Continue Keywords)


            उ े

           इस अ ास के  अंत म  आप यह कर सक  गे :
           •   Break और Continue  ेटम ट्स के  िसंटै  और उसके  उपयोग को जान
           •   Break और Continue  ेटम ट्स का उपयोग करके  Java  ो ाम डेवलप कर ।


           आव कताएं  (Requirements)
           उपकरण/साम ी (Tools/Materials)
           •   िवंडोज OS वाला PC/लैपटॉप
           •   JDK सॉ वेयर
           •   टे  एिडटर (िवजुअल  ू िडयो/स ाइम/नोटपैड)

            ि या (Procedure)


           टा  1: लूप म   ेक का उपयोग करना
           import java.util.Scanner;
           public class BreakExample {

            public static void main(String[] args) {
                   // This program searches for a specific number in a loop
                   Scanner scanner = new Scanner(System.in);

                   System.out.print(“Enter the target number: “);
                   int target = scanner.nextInt();
                   boolean found = false;
                   // Search for the target number in a loop

                   for (int i = 1; i <= 10; i++) {
                       if (i == target) {
                           found = true;

                           break;  // Exit the loop when the target number is found
                       }
                   }
                   if (found) {

                       System.out.println(“The target number “ + target + “ is found.”);
                   } else {
                       System.out.println(“The target number “ + target + “ is not found.”);

                   }
                   scanner.close();
               }
           }

           आउटपुट:


                                                           52
   61   62   63   64   65   66   67   68   69   70   71