samedi 16 janvier 2021

Java if conditions always hand off on "else" [duplicate]

Hi i was trying to programm a simple chatbot with java, but it is not working... :(. After the user have to choose the language he want to use, it always wil be on "else". The code is not showing any errors. I am sorry that my english is so bad but i am from german. Here my code:

import java.util.Scanner;

public class Chatbot {

public static void main(String[] args) {
    
    sprachenauswahl();  
    }
public static void sprachenauswahl() {
    String benutzereingabe_chat;
    Scanner scan = new Scanner (System.in);
    System.out.println("Hi :D, please write the language you want to use on the chatbot");
    System.out.println("Write DE for german or EN for english");

    benutzereingabe_chat = scan.nextLine();
    
    if (benutzereingabe_chat == "DE") {
        System.out.println("Okay der chatbot wird nun auf der Sprache Deutsch gestartet");
        chatbot_DE();
    } else if(benutzereingabe_chat == "EN") {
            System.out.println("Okay the chatbot is now starting in the language english");
            chatbot_EN();
    } else {
        sprachenauswahl();
    }
}

public static void chatbot_DE() {
    System.out.println("Schreibe irgendwas");
    Scanner scan = new Scanner (System.in);

    String benutzereingabe_chat = "lol";
    while(benutzereingabe_chat != "bb") {
        benutzereingabe_chat = scan.nextLine();
        System.out.println("miau"); 
        
    }
}

public static void chatbot_EN() {
    System.out.println("Write something");
    Scanner scan = new Scanner (System.in);

    String benutzereingabe_chat = "lol";
    while(benutzereingabe_chat != "bb") {
        benutzereingabe_chat = scan.nextLine();
        System.out.println("meow"); 
}
}


}

Aucun commentaire:

Enregistrer un commentaire