Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Q19-Given an array of N integers, your task is to calculate the sum of all the odd integers present in the array.
- Ans-import java.io.*;
- import java.util.*;
- class Main {
- public static void main (String[] args) {
- Scanner s=new Scanner(System.in);
- int N=s.nextInt();
- int arr[]=new int[N];
- for(int i=0;i<N;i++){
- arr[i]=s.nextInt();
- }
- int sum=0;
- for(int j=0;j<N;j++){
- if(arr[j]%2!=0){
- sum=sum+arr[j];
- }
- }
- System.out.print(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement