Ниже приведен рабочий код, который печатает только те числа, которые произошли последовательно:
public class dice
{
public static void main(String[] args)
{
String input = "11555677666551189988777"; //suppose you saved input using Scanner.Next() in 'input'
char[] number = new char[input.length()]; // will hold each distintive number
int[] occurence = new int[input.length()]; //will hold the occurence of that number
int j=0, distinct = 0, visited = -1;
for (int i = 0; i < input.length() - 1; i++)
{
// Counting occurrences of input[i]
while (input.charAt(i) == input.charAt(i + 1))
{
if(i!=0)
{
if (input.charAt(i) != input.charAt(i - 1))
{
number[j] = input.charAt(i);
distinct++;
j++;
}
}
else
{
number[j] = input.charAt(i);
distinct++;
j++;
}
i++;
if(i + 1 == input.length())
break;
}
}
for(int i = 0; i < distinct; i++)
{
int count = 1;
for(j = i+1; j < distinct; j++)
{
if(number[i] == number[j])
{
count++;
//To avoid counting same element again
occurence[j] = visited;
}
}
if(occurence[i] != visited)
occurence[i] = count;
}
System.out.println("----------------------------------------------");
System.out.println(" Element | Consecutive Occurence");
System.out.println("----------------------------------------------");
for(int i = 0; i < distinct; i++)
{
if(occurence[i] != visited)
System.out.println(" " + number[i] + " | " + occurence[i]);
}
System.out.printf("\nAll other numbers doesn't Occured Consecutively !!");
}
}
Вывод:
----------------------------------------------
Element | Consecutive Occurence
----------------------------------------------
6 | 3
1 | 1
4 | 1
All other numbers doesn't Occurred Consecutively !!!
Надеюсь, это то, что вы хотите,скажи мне, если тебе нужно что-то еще с этим сделать.