samedi 25 janvier 2020

How do I make this loop such that the output is the same as the input unless i press "end" then the programme ends?

Hi I am new to java programming and I have this code and I want to know how to make it run until i type "end" then it stops. Can anyone help? I keep getting an error

public static void main(String [] args){

    String code_trigger_starter_str = "start";
    String code_trigger_ender_str = "end";
    //boolean program_running_bool = false;

    Scanner kybd_inpt = new Scanner(System.in);
    String kybd_input_str = kybd_inpt.nextLine();


    re_run_word_input(code_trigger_starter_str,code_trigger_ender_str);

//  exit_code(code_trigger_ender_str);

    }


private static void re_run_word_input(String code_trigger_starter_str,String code_trigger_ender_str) {
    //boolean program_running_bool = true;

    System.out.println("Enter a word");
    Scanner kybd = new Scanner(System.in);
    String kybd_new_word = kybd.nextLine();


    //if(kybd_input_str.equals(code_trigger_starter_str));{

    //System.out.println(kybd_new_word);


        if(!kybd_new_word.equals(code_trigger_ender_str)) {
        System.out.println(kybd_new_word);
        }
        else {
            if   (kybd_new_word.equals(code_trigger_ender_str)) {

            System.out.println("Program ended");
            }
        }
    }

Aucun commentaire:

Enregistrer un commentaire