Java running 2 programs in parallel

Asked

Viewed 74 times

-1

I’m using intellj and I just started a free course. I challenged myself to make a code in which you put a date and the program says the day of the week, but when trying to run the code opens a small written window

 'DiaDaSemana' is not allowed to run in parallel. Would you like to stop the running one? 

PS: Diadasemana is the name of the program. The window has 2 buttons (Stop and Rerun) and (Cancel), no matter what I put always happens the same thing. It allows me to write in the terminal(Run) and does not run anything else, and the code does not stop running without anything happening, here is the code: PS: no error occurs.

public class DiaDaSemana {
    static public void main(String[] args) {
        int semana = 3;

        int dia = 22;               //ENTRE COM
        int mes = 7;                //OS SEUS
        boolean anoBicesto = false; //DADOS

        if (mes > 1) {

            if (anoBicesto == false) {    //Sem Ano Bicesto
                semana += 31 + 28;
            } else {                      // Com Ano Bicesto
                semana += 31 + 29;
            }
            mes -= 2;

            while (mes > 0) {       //Enquanto mes for maior q zero
                if (mes % 2 == 1) {      //Março == impar == 31
                    semana += 31;
                }
                if (mes % 2 == 0) {      //Abril == par == 30
                    semana += 30;
                }
            }
        }
        while (semana > 7) {     //tirando as semanas extras
            semana -= 7;
        }

        switch (semana) {        //Resultado!
            case 1:
                System.out.println("Domingo-Feriado");
                break;
            case 2:
                System.out.println("Segunda-Feira");
                break;
            case 3:
                System.out.println("Terça-Feira");
                break;
            case 4:
                System.out.println("Quarta-Feira");
                break;
            case 5:
                System.out.println("Quinta-Feira");
                break;
            case 6:
                System.out.println("Sexta-feira");
                break;
            case 7:
                System.out.println("Sabado-Feriado");
                break;
            default:
                System.out.print("ERRO...ERRO...ERRO");
                break;
        }
    }
}

2 answers

1

Face the problem ta in your code, the while of line 22 ta in infinite loop the value of "mes" is never changed so will not leave this loop ever

0

This error is not in the code. It’s something from Intellij. Apparently there is a program already running (maybe an old version that has gone into infinite loop) and you are trying to run it again while the previous run is still there running indefinitely.

What you have to do is abort the previous run.

Your code is also not the best and there is much in it that could be improved. But that would be subject to another question.

  • What should I do to abort the previous run? In my defense I started learning Java 3 days ago on the internet, and this is just the prototype

  • @Nioty You can try to locate it in windows task manager and kill the process.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.