How do I make my code run in a loop and ask the user “Try again Yes or no?”

后端 未结 4 1467
忘了有多久
忘了有多久 2021-01-29 16:03
import java.io.*;
public class Magic{

   static final int maxsize = 50;

    public static void main (String [] args) throws IOException{

      int i, j, k, l, n, key;         


        
相关标签:
4条回答
  • 2021-01-29 16:17

    Wrap the try/catch statement with a while loop.

    while(not true) {
        do foo()
    }
    
    0 讨论(0)
  • 2021-01-29 16:20

    Put your code that computes your magic square in a separate method, and have your input reading code in a while loop, that calls that method until the user presses N, for example.

    0 讨论(0)
  • 2021-01-29 16:20

    Check out the Scanner class.

    0 讨论(0)
  • 2021-01-29 16:28
    String tryAgain = "y";
    do
    {
       // you code
    
       System.out.println("Try again? enter \"y/n\".");
       tryAgain = System.in.readLine();
    
    }
    while(!tryAgain.equals("n"));
    
    0 讨论(0)
提交回复
热议问题