plz tell quickly i can also mark brainlist tell quickly no spamming.
Attachments:
Answers
Answered by
17
Question:-
WAP to accept 10 numbers and find the sum of all the numbers which are even numbers
Answer:-
import java.util.*;
class SumNum{
public static void main (String ar []){
Scanner sc=new Scanner (System.in);
System.out.println("Enter 10 numbers");
int S=0;
for(int I=1;I<=10;I++){
int n=sc.nextInt();
if(n%2==0)
S+=n;
}
System.out.println("Sum of even numbers are:-"+S);
}
}
Logic:-
- Initialise sum variable as 0
- Run a loop from 1 to 10
- Check if the number is even or not
- If yes, Calculate the sum of that number
Similar questions
Hindi,
3 months ago
Accountancy,
3 months ago
India Languages,
7 months ago
CBSE BOARD X,
11 months ago