Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class trial {
- public static void main(String args[])
- {
- Scanner src=new Scanner(System.in);
- System.out.println("Enter the size of array");
- int n=src.nextInt();
- int a[]=new int[n];
- int esum=0;
- int osum=0;
- for(int i=0;i<n;i++)
- {
- System.out.println("Enter the number");
- a[i]=src.nextInt();
- }
- System.out.println("The entered array is");
- for(int j=0;j<n;j++)
- {
- System.out.println(a[j]);
- }
- System.out.println("Even numbers in the array are");
- for(int k=0;k<n;k++)
- {
- if (a[k]%2==0)
- {
- System.out.println(a[k]);
- esum=esum+a[k];
- }
- }
- System.out.println("Odd numbers in the array are");
- for(int m=0;m<n;m++)
- {
- if (a[m]%2!=0)
- {
- System.out.println(a[m]);
- osum=osum + a[m]; // osum Awesome hehehe
- }
- }
- System.out.println("The sum of even numbers is "+esum);
- System.out.println("The sum of odd numbers is "+osum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement