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