0

(From Jungle Camping - Java) Why no output?

import java.util.Arrays; import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); String[] inputarray = input.split(" "); String output = ""; for (String x : inputarray) { if (x == "Grr"){ output += "Lion "; } else if (x == "Rawr"){ output += "Tiger "; } else if (x == "Ssss"){ output += "Snake "; } else if (x == "Chirp"){ output += "Bird "; } } System.out.println(output); } }

29th Aug 2021, 10:54 AM
Ethan
2 Antworten
+ 2
Try usig if(x.equals("Grr)"{} (To compare a string i will recommend to using .equals ) And same for others too
29th Aug 2021, 11:39 AM
Pariket Thakur
Pariket Thakur - avatar
+ 1
Excellent, well done, thanks.
29th Aug 2021, 12:15 PM
Ethan