Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. public class Plateau {
  2. public static void main(String[] args) {
  3. if (args.length < 3) {
  4. System.out.println("ERROR");
  5. return;
  6. }
  7. int[] plateauWerte = new int[args.length];
  8. for (int i = 0; i < args.length; i++) {
  9. plateauWerte[i] = Integer.parseInt(args[i]);
  10. }
  11. int length = 0;
  12. int index = -1;
  13.  
  14. boolean isPlateau = false;
  15.  
  16. int tempLength = length;
  17. int tempInd = index;
  18.  
  19. for (int i = 1; i < plateauWerte.length; i++) {
  20. if (plateauWerte[i] > plateauWerte[i - 1]) {
  21. isPlateau = true;
  22. tempInd = i;
  23. tempLength = 1;
  24. } else if (isPlateau && plateauWerte[i] == plateauWerte[i - 1]) {
  25. tempLength++;
  26. } else if (isPlateau && plateauWerte[i - 1] > plateauWerte[i]) {
  27. if (tempLength > length) {
  28. length = tempLength;
  29. index = tempInd;
  30. }
  31. isPlateau = false;
  32. }
  33. }
  34. if(index == -1 && length == 0){
  35. System.out.println("kein plateau");
  36. } else {
  37. System.out.println(index + " " + length);
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement