Results 1 to 3 of 3
  1. #1
    rhallmark is offline Member
    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Default No idea where these errors are coming from!?

    PURPOSE:
    decimal to hexadecimal

    ERRORS:
    line 44: "missing method body, or declare abstract
    line 47: "cannot find symbol
    line 82: " return outside method"

    CODE:

    import java.util.Scanner;

    public class Decimal2HexConversion
    {
    public static void main(String[] args)
    {
    Scanner s = new Scanner(System.in);

    System.out.print("Enter a number (or -1 to exit): ");

    int decimal = s.nextInt();


    if ( decimal == -1 )
    {
    //break; //kill the program
    System.exit(0);
    }
    else //in this else is where EVERYTHING happens
    {
    System.out.print(decimalToHex(decimal));
    }
    }





    public static String decimalToHex(int decimal)
    {
    String hexValue = " ";

    while (decimal > 0)
    {
    hexValue = toHexChar(decimal % 16) + hexValue; //thinking I should + decimal NOT + hexValue
    decimal = (decimal / 16);
    }
    return hexValue;
    }




    public static char toHexChar(int hexValue); //we are calling (decimal % 16) from decimalToHex hexValue
    {
    char hexChar = ' ';
    switch (hexValue)
    {
    case 0: hexChar = '0';
    break;
    case 1: hexChar = '1';
    break;
    case 2: hexChar = '2';
    break;
    case 3: hexChar = '3';
    break;
    case 4: hexChar = '4';
    break;
    case 5: hexChar = '5';
    break;
    case 6: hexChar = '6';
    break;
    case 7: hexChar = '7';
    break;
    case 8: hexChar = '8';
    break;
    case 9: hexChar = '9';
    break;
    case 10: hexChar = 'A';
    break;
    case 11: hexChar = 'B';
    break;
    case 12: hexChar = 'C';
    break;
    case 13: hexChar = 'D';
    break;
    case 14: hexChar = 'E';
    break;
    case 15: hexChar = 'F';
    break;
    }
    return hexChar;
    }

    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: No idea where these errors are coming from!?

    Did you have any questions? If there are error messages, please copy the full text and paste it here.

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: No idea where these errors are coming from!?

    Java Code:
    public static char toHexChar(int hexValue); //we are calling (decimal % 16) from decimalToHex hexValue
    {
    Whats that semicolon (;) doing there?

Similar Threads

  1. IDEA 10 give me compiler errors
    By yma16 in forum IntelliJ IDEA
    Replies: 1
    Last Post: 05-01-2011, 05:07 PM
  2. Jax is coming to the us!!!
    By blease87 in forum Reviews / Advertising
    Replies: 0
    Last Post: 03-04-2011, 12:21 PM
  3. Replies: 4
    Last Post: 01-04-2011, 12:36 AM
  4. Replies: 3
    Last Post: 03-08-2009, 01:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •