0
I got this Error from java Code
Error: String Cannot be converted to String[] Any Soloution https://code.sololearn.com/cn8Wm38esLq9/?ref=app
17 odpowiedzi
+ 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
+ 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();.
+ 1
Lpang i already edit my post the code link is there
+ 1
Thank you so much Denise Roßberg
+ 1
Booztay Your welcome :)
0
any code to show ?
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
0
Still got that error Taste
0
I change the code into nextLine();
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
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
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
0
Remove unused name variable
- 1
Done i edit my post
- 2
Good try imrove it for nothe thing