0

I got this Error from java Code

Error: String Cannot be converted to String[] Any Soloution https://code.sololearn.com/cn8Wm38esLq9/?ref=app

21st Feb 2020, 4:34 PM
Booztay
Booztay - avatar
17 Respuestas
+ 4
Booztay if(inputname.equals("Karl") || inputname.equals("Justin"){ System.out.println("Oh, so you are " + inputname + " nice to meet you"); } Read the lessons about if/else Read also about String.equals in the String lesson (you can't use == here) and read about boolean operators: or || , and && and so on
21st Feb 2020, 5:10 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
Booztay String[] name = {"justin", "karl"}; name = sc.nextInt(); name is a String array. And in the next line you want to assign an integer value to this variable. This does not work. You have to create a new variable: int age = sc.nextInt();.
21st Feb 2020, 4:57 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Lpang i already edit my post the code link is there
21st Feb 2020, 4:42 PM
Booztay
Booztay - avatar
+ 1
Thank you so much Denise Roßberg
21st Feb 2020, 5:12 PM
Booztay
Booztay - avatar
+ 1
Booztay Your welcome :)
21st Feb 2020, 5:13 PM
Denise Roßberg
Denise Roßberg - avatar
0
any code to show ?
21st Feb 2020, 4:36 PM
Taste
Taste - avatar
0
create a new variable for the input String inputName = sc.nextLine(); nextInt() will return int, thus assign it to String variable will cause an error
21st Feb 2020, 4:49 PM
Taste
Taste - avatar
0
Still got that error Taste
21st Feb 2020, 4:51 PM
Booztay
Booztay - avatar
0
I change the code into nextLine();
21st Feb 2020, 4:52 PM
Booztay
Booztay - avatar
0
create new variable. String[] name = {"justin", "karl"}; String inputName = sc.nextLine(); the error is similar with the int. nextLine return a String, so assign it to String[] variable cause an error
21st Feb 2020, 4:53 PM
Taste
Taste - avatar
0
if you want to change the value of name. assign it to an index of that variable name[0] = sc.nextLine(); //replace justin or name[1] = sc.nextLine(); //replace karl
21st Feb 2020, 4:54 PM
Taste
Taste - avatar
0
It worked now but i want like to use if else statement Example Input: Karl or Justin Output: Oh so you are (UsersName) nice to meet you im Justin or Karl
21st Feb 2020, 5:03 PM
Booztay
Booztay - avatar
0
Remove unused name variable
23rd Feb 2020, 7:51 AM
Sharofiddin
Sharofiddin - avatar
- 1
Done i edit my post
21st Feb 2020, 4:37 PM
Booztay
Booztay - avatar
- 2
Good try imrove it for nothe thing
23rd Feb 2020, 9:03 AM
Java
Java - avatar