Whats the use of plus?


#1
char answerChoice = 'C';

	switch (answerChoice) {

		case 'A': System.out.println("You answered: " + answerChoice + ". Please try again.");
							break; 

		case 'B': System.out.println("You answered: " + answerChoice + ". Please try again.");
							break;

		case 'C': System.out.println("You answered: " + answerChoice + ". That is correct!");
							break;

		case 'D': System.out.println("You answered: " + answerChoice + ". Please try again.");
							break;

		default:
			System.out.println("Please select a valid answer choice.");

	}

in this code what is the use of the plus sign before the variables used in switch cases?


#2

the plus signs are for concatenation, to concat the strings and variable


#3

will it work without the '+' or will it show an error without the '+'?


#4

well, go ahead and try what happens. I predict it will give an error


#5

It gave error. Thanks for the help.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.