Page 164 - CA_Blue( J )_Class10
P. 164

To input 5 numbers and print the sum of the even numbers and product of the odd numbers using
                Program 3
                             while loop.
                 1  import java.util.*;

                 2  class even_odd

                 3  {    public static void main ()
                 4      {
                 5          Scanner sc= new Scanner(System.in);

                 6          int n,i=1,se=0,po=1;
                 7          while(i<=5)

                 8          {
                 9              System.out.print("Enter a number: ");

                10              n=sc.nextInt();
                11              if(n%2==0)

                12                  se=se+n;
                13              else

                14                  po=po*n;
                15      i++;

                16          }
                17          System.out.println("Sum of Even numbers : "+se);

                18          System.out.println("Product of Odd Numbers : "+po);
                19      }

                20  }

              You will get the following output:
































                162162  Touchpad Computer Applications-X
   159   160   161   162   163   164   165   166   167   168   169