Computer Science, asked by rahul733, 1 year ago

computer class 9
java
Q1) write a program to enter a number and find out weather it is odd or even number

Answers

Answered by rahulseervi2003
0
import java.util.Scanner;public class Sum_Odd_Even { public static void main(String[] args) { int n, sumE = 0, sumO = 0; Scanner s = new Scanner(System.in); System.out.print("Enter the number of elements in array:"); n = s.nextInt(); int[] a = new int[n]; System.out.println("Enter the elements of the array:"); for(int i = 0; i < n; i++) { a[i] = s.nextInt(); } for(int i = 0; i < n; i++) { if(a[i] % 2 == 0) { sumE = sumE + a[i]; } else { sumO = sumO + a[i]; } } System.out.println("Sum of Even Numbers:"+sumE); System.out.println("Sum of Odd Numbers:"+sumO); }}
Answered by uashenoy05
2
bro i wrote this on my own

pls mark it as brainliest
Attachments:

uashenoy05: tnx for marking brainliest
Similar questions