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); } }
2 Antworten
+ 2
Try usig if(x.equals("Grr)"{}
(To compare a string i will recommend to using .equals )
And same for others too
+ 1
Excellent, well done, thanks.