I'm very new to programming and can't resolve the following problem.
I have a list of coordinates in type char that I need to transfer to numbers (type int). So for example char a should be int 0, char b - int 1 etc. So I build the following code using a switch statement. I want to call it as a method but I keep getting the following error: this method must return a result of type int. Could somebody please explain what I'm doing wrong? I've also tried using return instead of int .. = 0; but that didn't help either.
int x () {
char ch = 'c';
switch (ch)
{
case 'a':
int a = 0;
break;
case 'b':
int b = 1;
break;
case 'c':
int c = 2;
System.out.println(c);
break;
case 'd':
int d = 3;
break;
case 'e':
int e = 4;
break;
case 'f':
int f = 5;
break;
case 'g':
int g = 6;
break;
case 'h':
int h = 7;
break;
}
}
int a = 0,int b = 1etc. You should just writereturn 0;,return 1;etc. And you don't need the breaks.