fork download
  1. //a JAVA program to find if the number to be searched is present in the array
  2. import java.util.*;
  3. class search_array
  4. {
  5. public static void main (String[] args) throws java.lang.Exception
  6. {
  7. Scanner sc=new Scanner(System.in);
  8. int arr[]=new int[10];
  9.  
  10. for(int i=0;i<10;i++)
  11. {
  12. arr[i]=sc.nextInt();
  13.  
  14. }
  15. System.out.println("Array of 10 element entered by user is:");
  16. for(int i=0;i<10;i++)
  17. {
  18. System.out.println(arr[i]);
  19. }
  20.  
  21. int p=0,n=0,ev=0,od=0;
  22. for(int i=0;i<10;i++)
  23. {
  24. if(arr[i]<0)
  25. n++;
  26.  
  27. if(arr[i]>0)
  28. p++;
  29.  
  30. if(arr[i]%2==0)
  31. ev++;
  32.  
  33. if(arr[i]%2!=0)
  34. od++;
  35.  
  36.  
  37. }
  38.  
  39. System.out.println("number of positive numbers are:"+p);
  40. System.out.println("number of negative numbers are:"+n);
  41. System.out.println("number of even numbers are:"+ev);
  42. System.out.println("number of odd numbers are:"+od);
  43.  
  44.  
  45.  
  46.  
  47. }
  48. }
Success #stdin #stdout 0.13s 35968KB
stdin
4  5  2  6  1  -1  7  9  -3  3
stdout
Array of 10 element entered by user is:
4
5
2
6
1
-1
7
9
-3
3
number of positive numbers are:8
number of negative numbers are:2
number of even numbers are:3
number of odd numbers are:7