13:16 binary numeric string goto decimal

Source: Internet
Author: User

13:

Title Description

Write a program that accepts a hexadecimal numeric string and outputs the decimal string for that value. (multiple sets of simultaneous inputs)

Input Description:

Enter a hexadecimal numeric string.

Output Description:

The decimal string that outputs the numeric value.

Input Example:

0xA

Output Example:

10

Note: Integer.parseint (num,16) with system can be converted directly to the corresponding binary number

 Packageprctice01;ImportJava.util.Scanner;/*13: Title Description write out a program that accepts a hexadecimal numeric string, outputting the decimal string for that value. (Multiple sets of simultaneous input) input description: Enter a hexadecimal numeric string. Output Description: A decimal string that outputs the value. Input example: 0xA Output Example: Ten*/ Public classOx2shi { Public Static voidMain (string[] args) {Scanner Scanner=NewScanner (system.in);  while(Scanner.hasnextline ()) {string string=Scanner.nextline (); String= String.substring (2);        System.out.println (Func (string));; }            }//Public static void Main (string[] args) {//Scanner Scanner = new Scanner (system.in);//While (Scanner.hasnextline ())//        {//string string = Scanner.nextline ();//string = string.substring (2);//int result = Integer.parseint (string, +);//System.out.println (result);//        }////    }    Private Static intFunc (String string) {intCount = 0; Charch; intresult = 0; inttemp = 0;  while(Count <string.length ()) {CH= String.charat (String.Length ()-count-1); if(Ch <= ' Z ' && ch >= ' A ') {Temp= CH-' A ' + 10; }            Else if(Ch <= ' z ' && ch >= ' a ') {Temp= CH-' A ' + 10; }            Else if(Ch <= ' 9 ' && ch >= ' 0 ') {Temp= CH-' 0 '; }            Else  Break; Result+ = Temp*math.pow (16, Count); Count++; }        returnresult; }}

13:16 binary numeric string goto decimal

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.