Ajuda com erro em codigo

Pessoal acabei de entrar em um curso de Engenharia da Computacao aqui em Varsovia / Polonia. estou tendo bastante dificuldade de acompanhar o ritimo do curse de java. Estou tentando resolver o meu segundo exercicio mas so esta dando erro! alguem pode me dar uma luz onde estou errando?

o que o professor pede…

Write a program reading integers until zero is entered and printing the length of
the longest sequence of consecutive numbers of the same value (and this value). For
example, for
2 2 2 11 11 11 5 5 2 3 3 2 2 2 2
the result should be Longest sequence: 4 times number 2.
Do not use arrays, strings or any other kind of collections.

eu escrevi isso aqui…

  // Boolean for checking if there's a character in the sequence

   

 // Scan all numbers typed until 0 is typed

while (scanner.hasNext()) {

// Check for integer input

if (!scanner.hasNextInt()) {

   // Check for finishing program
    

        if (scanner.hasNext("q") || scanner.hasNext("Q"))


                  System.exit(0);



            // Checks if we do have a char in the sequence and just raises instruction once


               if(!hasChar) {
    

            // Instruction raise
         

       System.out.println("Please give an integer sequence");


                  hasChar = true;
        
    }
    

        // Scan next element, prevents infinite looping


            scanner.next();

}else {

      // Breaks outside loop if "0" is typed


            if (scanner.hasNext("0"))
      

          break;

            

// Scans integer and assign to an int
 

           sequence = scanner.nextInt();



               // Increases counting for reading number


               if (number == sequence) {
        

        counter++;

            

    // Checks if have found longer sequence


                  if (longestCount < counter) {

                     longestCount = counter;
    
                longestNumber = number;
           
     }

// If is a new number sequence, make this the reading number and start counting from 0

               } else {
            
    number = sequence;
              
  counter = 0;

}

   }

}

// If just one number was typed then the longest number of a sequence is the first

      if (longestCount == 0)
       
 longestNumber = sequence;

    

// Results print if there is only integers

      if (!hasChar)
        
System.out.println("Longest sequence: " + (longestCount + 1) + " times " + "number " + longestNumber);



     // Next line
  

  scanner.next();

}

}

// Thank you!

}

Sim, podemos… Mas para resolver um erro precisa ter um erro, certo? então cadê o erro?

Meu inglês é ruim.
Como o fórum é pt-BR, o ideal era que você fizesse a tradução, bem como explicasse qual seu problema, pois fora não fazer o que precisa fazer, não sobra nada.

Então vou fazer uso do meu portug ingrish que está na ferrugem.

Escreva um programa que leia as entradas de um usuário.
As entradas devem ser números inteiros.
Quando a entrada for 0, o programa deve ser encerrado.
Antes de encerrar o programa, deve ser impresso a maior [sequência de números consecutivos] (por que a redundância?) com o mesmo valor.

Por exemplo:
Se as entradas do usuário forem: {2,2,2,11,11,11,5,5,2,3,3,2,2,2,2}, deve ser impresso que:
A maior sequência de números inteiros com o mesmo valor é: 4, sendo o valor: 2.

Tem um problema neste exercício: a “lógica” está furada :ship: -> :cruise_ship:.
O programa não possui a integridade desejada, pois como ficaria a sequência {1,1,2,2}?
Qual seria o valor com a “maior sequência”? 1, ou 2?

Eu, particularmente (com redundância mesmo), acho um exagero bloquear o uso de arrays e strings (:thinking:?) ou qualquer outro tipo de coleção para um exercício cuja integridade da aplicação é questionável: encontrar a maior sequência de números consecutivos com o mesmo valor, sem fazer ressalvas.

Divirta-se:

package teste;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Efemera {

    private int sequenciaAtual, maiorSequencia, maiorValor, valorAtual;
    private boolean inicio = true;

    public static void main(String[] args) {
        Efemera ekemera = new Efemera();
        int resposta;
        System.out.println("Informe um valor inteiro, ou 0 para sair");

        try (Scanner scan = new Scanner(System.in)) {
            while (!ekemera.sair(resposta = getValor(scan))) {
                ekemera.atualizarSequencia(resposta);
            }
            System.out.println(ekemera.maiorValor == 0
                    ? "Nada foi informado"
                    : "\"Maior sequência\": " + ekemera.maiorSequencia + ", para o valor: " + ekemera.maiorValor
            );
        } catch (NumberFormatException | InputMismatchException ex) {
            System.err.println("Entrada inválida: encerrando a aplicação");
        }
    }

    private static int getValor(Scanner scan) {
        return scan.nextInt();
    }

    private void atualizarSequencia(int novoValor) {

        if (this.valorAtual == novoValor) {
            ++this.sequenciaAtual;
            if (sequenciaAtual > maiorSequencia) {
                this.maiorValor = novoValor;
                this.maiorSequencia = sequenciaAtual;
            }
        } else {

            this.valorAtual = novoValor;
            this.sequenciaAtual = 1;
            if (inicio) {

                this.maiorValor = novoValor;
                this.maiorSequencia = sequenciaAtual;
                inicio = false;
            }
        }
    }

    private boolean sair(int valor) {
        return valor == 0;
    }
}

Como vc não facilitou a tradução, agora se vire pra entender o while :smile_cat: .