Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ch3ex2 {
- public static void main(String[] args){
- Scanner in = new Scanner(System.in);
- int num1,num2,sum=0,counter,pro = 1;
- System.out.print("Enter two numbers: ");
- num1 = in.nextInt();
- num2 = in.nextInt();
- counter = num1;
- while(counter<=num2){
- if(counter % 2 == 0) sum += counter;
- counter++;
- }
- System.out.printf("The sum of even number is %d%nThe product of odd numbers is: ",sum);
- counter = num1;
- while(counter<=num2){
- if(counter % 2 == 1) pro *= counter;
- counter++;
- }
- System.out.print(pro);
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement