Math, asked by amarnat45161, 7 months ago

plz tell quickly i can also mark brainlist tell quickly no spamming.​

Attachments:

Answers

Answered by BrainlyProgrammer
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