Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
Put parts of switch case in seperate methods possible?

So I have a big switch case in my main method. However it is way to long. I had the idea to put the different cases in a method each however, all of the cases contain break;and you obviously need a loop or switch case for a break;The break is also within the code. Any ideas on how I can do this?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can make separate methods/functions for each action. Then inside the switch statement, you can call these methods. But if you want to avoid the switch statement, you can use Enums for different cases for example. So it would look something like this:

int f1(int arg1, int arg2...) {
    //do something
}

void f2(int arg1, int arg2...) {
    //do something
}

public static void main() {
    switch(statement){
        case 0:
            f1();

            break;

        case 1:
            f2();

            break;
    }
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda