Write a program to input twelve different numbers . Display the sum and product of only the even numbers
by using for-loop. In java
Answers
Answered by
2
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double num = 0, sum = 0;
for(int i = 1; i <= 12; i++) {
System.out.println("Enter Number "+i+": ");
num = sc.nextDouble();
if(num % 2 == 0) {
sum = sum + num; // sum+=num
}
}
System.out.println("Sum of the Even Numbers = "+sum);
}
}
Similar questions