What is the problem in this code ? | SoloLearn: Learn to code for FREE!

-1

What is the problem in this code ?

https://code.sololearn.com/cGwtfBybVcr7/?ref=app

7/3/2020 5:26:20 AM

Dawit Hadush

5 Answers

New Answer

+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 😉 */

+5

use this import java.util.Scanner; class MyClass { public static void main(String[] args) { Scanner myName = new Scanner(System.in); String name = myName.nextLine(); if(name.equals("Dawit")) { System.out.println("Wellcome !!!"); } else { System.out.println("Who are you ?"); } }

+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

+2

Bro, your code is all correct.....I don't know where are you getting the error.