Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Help for java beginner

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    4
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help for java beginner

    import java.util.Scanner;
    2
    3 public class HexToDecimalConversion {
    4 /** Main method */
    5 public static void main(String[] args) {
    6 // Create a Scanner
    7 Scanner input = new Scanner(System.in);
    8
    9 // Prompt the user to enter a string
    10 System.out.print("Enter a hex number: ");
    11 String hex = input.nextLine();
    12
    13 System.out.println("The decimal value for hex number "
    14 + hex + " is "+ );
    15 }
    16
    17 public static int hexToDecimal(String hex) {
    18 int decimalValue = 0;
    19 for (int i = 0; i < hex.length(); i++) {
    20 char hexChar = hex.charAt(i);
    21 decimalValue = decimalValue * 16 + hexCharToDecimal(hexChar);
    22 }
    23
    24 return decimalValue;
    25 }
    26
    27public static int hexCharToDecimal(char ch) {
    28 if (ch >= 'A' && ch <= 'F')
    29 return 10 + ch - 'A';
    30 else // ch is '0', '1', ..., or '9'
    31 return ch - '0';
    32 }
    33 }



    the above code implements the hexToDecimal(String
    hexString) method, which converts a hex string into a decimal number. Implement
    the hexToDecimal method to throw a NumberFormatException if the
    string is not a hex string.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help for java beginner

    Please don't post multiple copies of the same question. I deleted your duplicate thread.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help for java beginner

    Also, please see the link in my signature on asking questions the smart way before you post again. For example, what's your actual question? Where are you stuck? Simply dumping your homework assignment here is not going to get you very far.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Help for java beginner

    To add to the advice given by Kevin, here's some recommended reading: http://www.javaprogrammingforums.com...-get-help.html

  5. #5
    Junior Member
    Join Date
    Oct 2011
    Posts
    4
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help for java beginner

    Its not an homework assignment ,i started learning java and was stuck with a question that i am trying to do .So just asked for help.That's it

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help for java beginner

    Quote Originally Posted by sarasaleem View Post
    Its not an homework assignment ,i started learning java and was stuck with a question that i am trying to do .So just asked for help.That's it
    Okay, that's fine, but that doesn't make it any easier to answer a question that has not been asked.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member
    Join Date
    Oct 2011
    Posts
    4
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help for java beginner

    Anyways thanks for your advice i already solved it by myself .

Similar Threads

  1. Java projects for beginner
    By hexwind in forum Java Theory & Questions
    Replies: 5
    Last Post: August 8th, 2011, 08:05 PM
  2. Another beginner to Java!
    By jwise95 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 21st, 2011, 04:27 PM
  3. [SOLVED] Java beginner is confused....
    By truebluecougarman in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 27th, 2011, 08:50 AM
  4. Java Beginner Here!
    By j3nn42o in forum The Cafe
    Replies: 10
    Last Post: January 10th, 2011, 04:57 AM
  5. Java Beginner
    By rannoune in forum Java Theory & Questions
    Replies: 3
    Last Post: December 25th, 2009, 03:30 AM