New course! Every coder should learn Generative AI!
Try a free lesson- 1
What is the problem in this code ?
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 😉
*/
+ 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")
+ 2
Thanks
+ 2
Bro, your code is all correct.....I don't know where are you getting the error.