+ 2
How do I do the jungle camping code coach?
I've been trying to get this but I can't figure out how to take and process a random number of inputs.
10 Respostas
+ 5
Yaye
Hint convert string input to string array.
And use Equals method to compare string You can't compare with ==
Print the value if string is matching.
string s1 = Console.ReadLine();
string[] arr = s1.Split(" ");
for (int i = 0; i < arr.Length; i++) {
if (arr[i].Equals("Grr"))
Console.Write("Lion ");
else if (arr[i].Equals("Rawr"))
Console.Write("Tiger ");
else if(arr[i].Equals("Ssss"))
Console.Write("Snake ");
else if(arr[i].Equals("Chirp"))
Console.Write("Bird ");
}
+ 10
I Am AJ ! , in the microsoft docs you can find this:
By default, the most common operations for string comparison are:
▪︎String.Equality and String.Inequality, that is, equality operators == and !=, respectively
▪︎String.CompareTo()
▪︎String.Equals()
so for me there is no good or bad between these variants.
+ 9
Yaye , before we can help you, you should show us your attempt first. if you have not done a try by yourself upto now, please do so. Put your code in playground and link it here. Thanks!
+ 9
I Am AJ ! , just a comment to your posts:
▪︎you mentioned " ... use Equals method to compare string. You can't compare with =="
--->>> this statement is not true, you can use also "==" to compare strings:
....
if (arr[i] == "Grr")
....
is also working perfect.
+ 3
Lothar It will work but it's bad checking. I don't know in C# but if you talk about Java, Sonar is a tool which tells don't compare string with == always use equals method.
+ 1
Thanks AJ. Thanks to you I was able to do it
+ 1
Yaye
== compares object and two objects can't be same.
Equals compare values.
0
And what's the difference between "==" and ". Equals"
0
Oh okay, cool thanks