dimanche 31 juillet 2016

i want my statement to re-execute if the condition if met false

So what i want to happen is that when the input is not "start" the if statement should run again asking for the user to input "start". any ideas would be helpfull. thanks :) example:

import java.util.Scanner;

import java.util.Random;
public class Words {
    public static void main(String[]args){


        Scanner scan = new Scanner(System.in);
        String words[] = {"Iterate","Petrichor"};

        System.out.println("type *start* to begin");
        String input = scan.nextLine();

        if (input.equals("start")){
            String random = (words[new Random().nextInt(words.length)]);
            System.out.println(random);
        }
    }

}

Aucun commentaire:

Enregistrer un commentaire