Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. 1 import java.util.*;
  2. 2 public class Problema {
  3. 3 public static void main(String[] args) {
  4. 4 Scanner scanner = new Scanner(System.in);
  5. 5 double[] numere;
  6. 6 int k;
  7. 7 int nrElemente = scanner.nextInt();
  8. 8 numere = new double[nrElemente];
  9. 9 for (int i=0;i<nrElemente;i++) {
  10. 10 numere[i] = scanner.nextDouble();
  11. 11 }
  12. 12 int elemPozitive = 0;
  13. 13 int indexMax = 0;
  14. 14 for (int i=0;i<nrElemente;i++) {
  15. 15
  16. 16 if (numere[i]>0) {
  17. 17 k = 0;
  18. 18 while(numere[i+k]>0) {
  19. 19 k++;
  20. 20 if (i+k==nrElemente)
  21. 21 break;
  22. 22 }
  23. 23
  24. 24 if (k > elemPozitive) {
  25. 25
  26. 26 elemPozitive = k;
  27. 27 indexMax = i;
  28. 28 }
  29. 29
  30. 30
  31. 31 }
  32. 32 }
  33. 33 if (elemPozitive == 0)
  34. 34 indexMax = -1;
  35. 35 System.out.println(indexMax);
  36. 36 System.out.println(elemPozitive);
  37. 37 }
  38. 38
  39. 39 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement