I am doing a simple exercise but it shows me some error icons
Can you explain to me what is being done wrong, I am following all the correct steps, I do not observe that there are code syntax errors.
This is the code
package exampleswitch;
import javax.swing.*;
public class ExampleSwitch {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
char cuestionario;
cuestionario = 'Tema:';
int semana;
semana = 1;
switch(semana){
case 1:
cuestionario += 'Introducción a la programación';
break;
case 2:
cuestionario += 'Secuenciación y selección';
}
}
}
You are defining the quiz variable as a char. That is, a character. For multiple characters, you need a string (or an array of char, but I don't think that's what you're looking for).
Change the definition of the variable to be of type string.
Edit because there is a very important comment: when handling multiple characters, double quotes are used to demarcate them.
For your case, it is not possible to use
char
.Char
It is used to store a character such as'a'
or'A'
with single quotes.Now to store a set of characters, use
String
. This type is usually enclosed in double quotes""
I leave your example of how it would look:
I have left a series of comments on your code. If you have any questions/problems, don't be afraid to ask.
You are defining wrong, it should be: