Advertisement
Guest User

Untitled

a guest
Feb 15th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. package buchstabenkette;
  2. import java.util.*;
  3.  
  4. public class zaehlen {
  5. public static void main(String args[]) {
  6. String str = "abaababaabbabbaabbbbaaaaabbaaabbbbbba";
  7. char[] strArr = str.toCharArray();
  8. int cnt=0;
  9. ArrayList<Integer> countsAoB = new ArrayList<>();
  10.  
  11. ArrayList<Integer> moeglichkeiteins = new ArrayList<>();
  12. ArrayList<Integer> moeglichkeitzwei = new ArrayList<>();
  13. ArrayList<Integer> moeglichkeitdrei = new ArrayList<>();
  14.  
  15.  
  16. // a oder b anhand des letzten im String
  17. char last = strArr[strArr.length-1];
  18.  
  19. for (int i = 0; i < strArr.length; ++i)
  20. {
  21. if(strArr[i]==last)
  22. {
  23. cnt++;
  24. }
  25. else
  26. {
  27. if(cnt>0)
  28. {
  29. countsAoB.add(cnt);
  30. }
  31.  
  32. cnt=0;
  33. }
  34. }
  35.  
  36. int letztezahl = countsAoB[countsAoB.length-1];
  37.  
  38.  
  39. // alle zahlen die über der letzten sind und sie selber
  40.  
  41. for (int i; i<countsAoB; i++){
  42.  
  43. if (countsAoB[i] == letzteZahl){
  44. count++
  45. } else {
  46. count = 0;
  47. moeglichkeitzwei.add(count);
  48. }
  49. }
  50. // Groeßer: Zahlen die größer sind als die letzte zahl:
  51.  
  52.  
  53. for (int i : countAoB){
  54. if (i >= letzteZahl){
  55. moeglichkeiteins.add(i);
  56. }
  57. }
  58.  
  59. System.out.println(Arrays.toString(countsAoB.toArray()));
  60. System.out.println(Arrays.toString(moeglichkeiteins.toArray()));
  61. System.out.println(Arrays.toString(moeglichkeitzwei.toArray()));
  62. System.out.println(Arrays.toString(moeglichkeitdrei.toArray()));
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement