Computer Science, asked by nishaumashankaran, 1 year ago

Write a java program to input 10 numbers from the user and add all the odd numbers together and even numbers together and also print all the user given numbers in the following output:
_,_,_,_,_,_,_,_,_,_ are the numbers given by you

Answers

Answered by AryaPriya06
3
import java.util.Scanner;

public class Even_Odd

{

public static void main(String[] args)

{

int n;

Scanner s = new Scanner(System.in);

System.out.print("Enter no. of elements you want in array:");

n = s.nextInt();

int a[] = new int[n];

System.out.println("Enter all the elements:");

for (int i = 0; i < n; i++)

{

a[i] = s.nextInt();

}

System.out.print("Odd numbers:");

for(int i = 0 ; i < n ; i++)

{

if(a[i] % 2 != 0)

{

System.out.print(a[i]+" ");

}

}

System.out.println("");

System.out.print("Even numbers:");

for(int i = 0 ; i < n ; i++)

{

if(a[i] % 2 == 0)

{

System.out.print(a[i]+" ");

}

}

}

}

Output:

$ javac Even_Odd.java $ java Even_Odd   Enter no. of elements you want in array:5 Enter all the elements: 1 2 3 4

If this helps then plzzzzz mark me brainliest.

AryaPriya06: its ok but don't dare to ask such things again
AryaPriya06: gud
AryaPriya06: do u got ur result
AryaPriya06: oh
AryaPriya06: in which class
Similar questions