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
1 Antwort
+ 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.