What is wrong here? Thanks for help :). German answers are very nice , bit English also ok. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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