mercredi 29 septembre 2021

If statement gives error, program works perfectly without it

sorry if the answer is too obvious. This is for an assignment I am working on, so since I need and want to learn it by mistake, I will just post what I think is messing up my code.

      keyboard.useDelimiter("[*\\s]+");
      
      int månad, dag;
      double sek, minutdelat1, minutdelat2, timmeupp,
      minutupp, timmened, minutned, soltimmar, wh, produktion;
    
      System.out.print("Skriv dagens datum [mm-dd]: ");
      String response = keyboard.next();

      månad = keyboard.nextInt();
      dag = keyboard.nextInt();
      keyboard.nextLine();
      
      if (månad >= 06 && månad <= 07)
         {
         System.out.print("Skriv in tidpunkt soluppgång [hh:mm]: ");

         }
     else 
        {
         System.out.print("Fel månad, programet stängs");
        }```

Without the "if" code, the program runs perfectly. If it is not understandable, then I want the the "mm" (month) to be synced to "månad" and if the month is not 06 or 07, then the program will close, if it is correct then it will continue.

If I just write "07" "06" 3 times then it will go on to the next question but if I write for example "07-18" then I will get an error. I think the "-" is missing the code up.

It is important that I learn this myself so please just point me in the right way, and since this is beginning Java, please no advance programming. Thank you!

Aucun commentaire:

Enregistrer un commentaire