Advertisement
Guest User

ssssssss123

a guest
Sep 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. public static void main (String[] args)
  2. {
  3. int n , sum = 0, even=0,odd=0, average=0, avcount = 0 ;
  4. Scanner s = new Scanner (System.in);
  5. System.out.print("Enter no. of elments in array ");
  6. n = s.nextInt();
  7. int a[] =new int[n];
  8. for(int i=0; i<n;i++){
  9.  
  10. a[i]=i;
  11. sum = sum +i;
  12. if (i%2==0){
  13. even +=1;
  14. }
  15. else
  16. {
  17. odd+=1;
  18. }
  19.  
  20.  
  21. }
  22. average = sum/n ;
  23.  
  24. System.out.println("Sum of all the array elements is "+sum);
  25. System.out.println("The average of the array elements is"+average);
  26. System.out.println("The number of even numbers in the array is "+even);
  27. System.out.println("The number of odd numbersw in the array is "+odd);
  28.  
  29. for (int j =0; j<n;j++){
  30. a[j]=j;
  31. if (j>=average){
  32. avcount +=1;
  33. }
  34. }
  35. System.out.println("The number of elements grater than the average is "+avcount);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement