What is the problem in this code ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1
3rd Jul 2020, 5:26 AM
Dawit Hadush
Dawit Hadush - avatar
4 Answers
+ 3
import java.util.Scanner; class MyClass { public static void main(String[] args) { Scanner myName = new Scanner (System.in); String name = myName.nextLine(); String cap = name.toLowerCase(); if (cap.equals("dawit")){ System.out.println("Wellcome !!!"); } else { System.out.println("Who are you ?"); } } } /* This will make it case insensitive 😉 */
14th Jul 2020, 8:02 AM
Samuel
Samuel - avatar
+ 4
you shouldnt use == when comparing the value of String. it'll try to compare the reference of the object. try .equals(str) instead ex. name.equals("Dawit")
3rd Jul 2020, 6:03 AM
Taste
Taste - avatar
+ 2
Thanks
3rd Jul 2020, 6:14 AM
Dawit Hadush
Dawit Hadush - avatar
+ 2
Bro, your code is all correct.....I don't know where are you getting the error.
3rd Jul 2020, 8:56 AM
Arya Deep Chowdhury
Arya Deep Chowdhury - avatar