What is wrong here? Thanks for help :). German answers are very nice , bit English also ok. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

What is wrong here? Thanks for help :). German answers are very nice , bit English also ok.

import java.util.Scanner; import java.util.Random; public class Chatbot { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String eingabe = sc.nextString(); if (eingabe == Hey) { } System.out.println("I am fine Thanks"); } }

10th Mar 2017, 9:39 PM
nwytg
7 Answers
+ 14
- Use sc.nextLine() - You should check string equality with if eingabe.equals("Hey") Your code could compile if you didn't miss the surrounding double quotes: "Hey". But it's better to use equals method. Btw you don't use imported Random class and you will always output 'I am fine...', because the println call is outside the curly braces. - Verwende sc.nextLine() - Die Gleichheit von Strings solltest du mit if eingabe.equals("Hey") prüfen. Das Kompilieren würde auch so funktionieren, wenn du nicht die Anführungsstriche vergessen hättest: "Hey". Aber nimm lieber die equals-Methode. Übriges benutzt du die importierte Klasse Random nicht und die Ausgabe wäre immer 'I am fine...', weil der Aufruf von println außerhalb der geschweiften Klammern erfolgt.
10th Mar 2017, 9:55 PM
Tashi N
Tashi N - avatar
+ 10
if (eingabe.equals("hey")){ //... }
11th Mar 2017, 7:47 AM
Tashi N
Tashi N - avatar
+ 3
Yes thanks, I will use the random class later, this was only the first part of the Programm. But thanks for the help with the Scanner :)☺ Ja danke, ich werde die Random Klasse später benutzen, das war nur der erste Teil von meinem Programm. Aber danke für die hilfe mit dem Scanner :). 👍
11th Mar 2017, 7:34 AM
nwytg
+ 3
Oh ups . Thank you tashi ❤
11th Mar 2017, 7:50 AM
nwytg
+ 2
that's it you should change the method of eingabe and thé if condition with the method equals("Hey") not the if(eingabe == Hey){ Système.out.println("I am fine thank."); } Sorry for the english
10th Mar 2017, 10:21 PM
Aboubacar Traore
Aboubacar Traore - avatar
+ 2
Here is my new Programm and it doesnt works :(. import java.util.Scanner; import java.util.Random; public class Chatbot { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String eingabe = sc.nextLine(); if eingabe.equals("hey") { System.out.println("I am fine Thanks"); } } }
11th Mar 2017, 7:46 AM
nwytg
+ 1
Try writing your programs on the computer, it will show you the errors before you run it, it'll help you a lot.
10th Mar 2017, 10:22 PM
David Koplik
David Koplik - avatar