Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package buchstabenkette;
- import java.util.*;
- public class zaehlen {
- public static void main(String args[]) {
- String str = "abaababaabbabbaabbbbaaaaabbaaabbbbbba";
- char[] strArr = str.toCharArray();
- int cnt=0;
- ArrayList<Integer> countsAoB = new ArrayList<>();
- ArrayList<Integer> moeglichkeiteins = new ArrayList<>();
- ArrayList<Integer> moeglichkeitzwei = new ArrayList<>();
- ArrayList<Integer> moeglichkeitdrei = new ArrayList<>();
- // a oder b anhand des letzten im String
- char last = strArr[strArr.length-1];
- for (int i = 0; i < strArr.length; ++i)
- {
- if(strArr[i]==last)
- {
- cnt++;
- }
- else
- {
- if(cnt>0)
- {
- countsAoB.add(cnt);
- }
- cnt=0;
- }
- }
- int letztezahl = countsAoB[countsAoB.length-1];
- // alle zahlen die über der letzten sind und sie selber
- for (int i; i<countsAoB; i++){
- if (countsAoB[i] == letzteZahl){
- count++
- } else {
- count = 0;
- moeglichkeitzwei.add(count);
- }
- }
- // Groeßer: Zahlen die größer sind als die letzte zahl:
- for (int i : countAoB){
- if (i >= letzteZahl){
- moeglichkeiteins.add(i);
- }
- }
- System.out.println(Arrays.toString(countsAoB.toArray()));
- System.out.println(Arrays.toString(moeglichkeiteins.toArray()));
- System.out.println(Arrays.toString(moeglichkeitzwei.toArray()));
- System.out.println(Arrays.toString(moeglichkeitdrei.toArray()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement