Jungle Camping Challenge | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Jungle Camping Challenge

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); String noises = input.nextLine(); while (char = g || r || s || c){ switch (noises){ case g: System.out.println("Lion"); case r: System.out.println("Tiger"); case s: System.out.println("Snake"); case c: System.out.println("Bird"); break; } } } } Im not too sure where to go from here

11th Dec 2020, 10:00 PM
Ben Szydlowski
1 Answer
+ 2
In this task you need to split the given sentence into words and then switch each word into their corresponding sound. Read about split() method in the String class. But here in your code, you are not taking account of each word. In Java, a char is written inside two apostrophes ' '. e.g. char c = 'c'; Also the definition of your while loop is wrong. You're missing identifier after char. Compiler wouldn't know what are r, s, c. Also take note that both 'g' and 'G' are different.
12th Dec 2020, 2:10 AM
Minho
Minho - avatar