0

Please help me make an infinite loop: after the cases show their answer, the program should instantly ask the user again.

package calendartool;

import java.io.Console;

public class CalendarTool {


    public static void main(String[] args) {

        Console C = System.console();
        int month = Integer.parseInt(C.readLine("Please put a valid month: \n"));
        int year = Integer.parseInt(C.readLine("Please put a valid year: \n"));

            switch (month) {
                case 1:
                    System.out.println("The month is January!");
                    System.out.println("January has 31 days!");
                    break;

            }



    }
}
Katriel
  • 120,462
  • 19
  • 136
  • 170
ihatecodes
  • 61
  • 4

4 Answers4

4

i prefer, but it's a matter of taste...

while(true){
}
PbxMan
  • 7,525
  • 1
  • 36
  • 40
1

The infinite loop:

while(true) {
    //Your code here
}
Tom G
  • 3,650
  • 1
  • 20
  • 19
1

I've always been partial to:

for(;;)
{
    //Do stuff
}

If only because it's quicker to type.

MrLore
  • 3,759
  • 2
  • 28
  • 36
0

Use do-while loop to ask user that he wants to continue or not.

br is bufferredreader instance variable.

 char ch=(char)br.read();
 do
 {
System.out.println("press 1 for month jan");
System.out.println("do you want to continue(Y/N)");

}
while(ch=='Y'||ch=='Y');
Abhishekkumar
  • 1,102
  • 8
  • 24