Switch Statement: Set charvariable penaltyKick value to L, R, or C


#1

How do I do this?

public class Switch {
public static void main(String[] args) {

    char penaltyKick = 'L' 'R' 'C';

    switch (penaltyKick) {

        case 'L': System.out.println("Messi shoots to the left and scores!");
                            break; 
        case 'R': System.out.println("Messi shoots to the right and misses the goal!");
                            break;
        case 'C': System.out.println("Messi shoots down the center, but the keeper blocks it!");
                            break;
        default:
            System.out.println("Messi is in position...");

#2

Just found this on the forum without having tried the Java course yet, so I'm not sure about the context, but your problem is the line:

char penaltyKick = 'L' 'R' 'C';

That doesn't make any sense. You can only have one value on the right side of the assignment. I'm guessing you should chose 'L','R' OR 'C'.
Like this if you choose 'L':

char penaltyKick = 'L' ;


#3

But it's telling me to enter the following,
"Look at the code in the code editor. Set the char variable penaltyKick value to L, R, or C."


#4

I tried to choose just one value: L. but it wouldn't work.


#5

I am also having the same problem


#6

Could you post a screen shot showing the problem?


#7


#8

@courserockstar46575

It looks like you have your green light there but didn't actually do the task properly -- is that right?


#9

public class Switch {
public static void main(String[] args) {

	char penaltyKick = 'L';

	switch (penaltyKick) {

		case 'L': System.out.println("Messi shoots to the left and scores!");
							break; 
		case 'R': System.out.println("Messi shoots to the right and misses the goal!");
							break;
		case 'C': System.out.println("Messi shoots down the center, but the keeper blocks it!");
							break;
		default:
			System.out.println("Messi is in position...");

	}

}

}

So I tried this and it worked..only problem is that the instructions did not tell me to do this,,instead it told me this: Look at the code in the code editor. Set the char variable penaltyKick value to L, R, or C.

I think theirs just a problem with the directions..hopefully they realize it and fix it.


#10

Something like:

Set the char variable penaltyKick value to one of L, R, or C.


#11

Yea I understood what it meant by L, R, or C...

but it still felt confusing at first i only came to realize what was the problem when i came on here haha


#12

i think your problem is you are setting the char penaltyKick value to for example L it is returning error coz it is missing apostrophe since it is a character, so set the value to 'L' instead of L
and your code should look like this


#15