Advertisement
ABaDy1996

ex2 ch4

Oct 3rd, 2020
1,334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class ch3ex2 {
  3.     public static void main(String[] args){
  4.         Scanner in = new Scanner(System.in);
  5.         int num1,num2,sum=0,counter,pro = 1;
  6.         System.out.print("Enter two numbers: ");
  7.         num1 = in.nextInt();
  8.         num2 = in.nextInt();
  9.         counter = num1;
  10.         while(counter<=num2){
  11.             if(counter % 2 == 0) sum += counter;
  12.             counter++;
  13.         }
  14.         System.out.printf("The sum of even number is %d%nThe product of odd numbers is: ",sum);
  15.         counter = num1;
  16.         while(counter<=num2){
  17.             if(counter % 2 == 1) pro *= counter;
  18.             counter++;
  19.         }
  20.         System.out.print(pro);
  21.         in.close();
  22.        
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement