//I am passing a hex as a string into a decimal integer and I know Integer.parseInt() is easier but i can not use it.
//Look below two areas have illegal start of expression and one with not a statement.

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

int total=0;
total=parseHex("ABC");
System.out.println("Hex String ABC = Decimal:"+total);

}

public static int parseHex(String hex)

{
int decValue;
int length=hex.length();
int total;
for (int i=0;i<length;i++)
{

decValue=getValue(hex.CharAt(i));
total= total +(int)(decValue*(Math.pow(16, length-1-)));//illegal start of expression
}
return total;
}

public static int getValue(char c)
{
int hold;
switch (c)
{

case:('0'); //illegal start of expression and not a statement
hold=0;
break;
}
}


}

The compiler keep telling me I have to return something inside my method what do i have to return??
I thought that the break is the return??

public static int getValue(char c)
{
int hold;
switch (c)
{

case '0':
break;
}
}


}

The break; takes you out of the switch{}.
Even if it did take you out of the method, which it doesn't, the method is declared int:

public static int getValue(char c) {}

The above method has ONE char argument,
and it must return an int value.
If you you don't want it to return anything it should be void: public static void getValue(char c) {}

or else you will need somewhere in your method, probably at the end, a return statement which will return the int that you want to return

public static int getValue(char c)
{
int hold;
switch (c)
{

case '0': 
break;
}
}

Where is your return statement ? use an approprimate return value .

It looks like that you are baby-new to Java .
[1] . You does not indent the code , (bad pratice )
[2] . You does not know the basic language core

anyway take this easy . what about learning some language fundermantals anyway . Try to
download the Think in Java here ,
http://mindview.net/Books/DownloadSites/
and This book is completely leagal . dont worry to download it . I get banned publishing the links to illeagal books in here .

however try this ,

public static int getValue(char c)
{
    int hold;   // why do you create this ?
    switch (c)
   {

      case '0':
           return 0;
          
      case '1':
          return 1;
      // other 

     case '9':
         return 9;
   }
}

anyway , with there is a easiear way to done this , use java api for this ,

change this line to this also
total= total +(int)(decValue*(Math.pow(16, length-1-)));//illegal start of expression
to
total= total +(int)(decValue*(Math.pow(16, length-1)));//illegal start of expression

This article has been dead for over six months. Start a new discussion instead.