1. public class naloga_3 {
  2. public static void main(String[] args) {
  3. int[] stevilo = new int[1000];
  4. int vsota_p = 0, poz = 0, vsota_n = 0, neg = 0, max = 0, prva_poj = 0, zadnja_poj = 0;
  5. boolean _prva_poj = false;
  6. for(int i = 0; i < stevilo.length; i++) {
  7. stevilo[i] = (int)Math.round(Math.random() * 2000 - 1000);
  8.  
  9. if(stevilo[i] < 0) {
  10. vsota_n += stevilo[i];
  11. neg++;
  12. }
  13.  
  14. if(stevilo[i] > 0) {
  15. vsota_p += stevilo[i];
  16. poz++;
  17. }
  18.  
  19. if(i == 0 || stevilo[i] > max) {
  20. max = stevilo[i];
  21. }
  22. }
  23.  
  24. vsota_n /= neg;
  25. vsota_p /= poz;
  26.  
  27. int vsota = vsota_n + vsota_p;
  28. System.out.println("Povprecje negativnih stevil je: " + vsota_n);
  29. System.out.println("Povprecje pozitivnih stevil je: " + vsota_p);
  30. System.out.println();
  31. System.out.println("Stevila vecja od povprecja vseh stevil, ki je " + vsota + ":");
  32. for(int i = 0; i < stevilo.length; i++) {
  33. if(stevilo[i] > vsota) {
  34. System.out.println(stevilo[i]);
  35. }
  36.  
  37. if(stevilo[i] == max) {
  38. if(_prva_poj != true) {
  39. prva_poj = i;
  40. _prva_poj = true;
  41. }
  42. zadnja_poj = i;
  43. }
  44. }
  45.  
  46. System.out.println("Mesto prve pojavitve max stevila je na indexu: " + prva_poj);
  47. System.out.println("mesto zadnje pojavitve max stevila je na indexu: " + zadnja_poj);
  48. }
  49. }