Home > Net >  High marks, data type conversion
High marks, data type conversion

Time:12-18

Int I=10;
Byte b;

Requirements () function converts a decimal number I hex 0 and assign a value to the byte type b, which requires to get the following results:

B=0 x0a;

CodePudding user response:

A face of meng force

CodePudding user response:

import java.util.Scanner;

Public class Main {
Public static void main (String [] args) {
Scanner Scanner=new Scanner (System. In);
String String=scanner. NextLine ();//input hexadecimal number
int sum=0;
for(int i=0; i{
Int m=string charAt (I);//the input hexadecimal string into individual characters
Int num=m>='A'? M - 'A' + 10: m - '0';//will turn numerical characters corresponding to the ASCII value of the
Sum +=math.h pow (16, string. The length () - 1 - I) * num.
}
System. The out. Println (sum);
}
}

CodePudding user response:

refer to the second floor weixin_43268649 response:
import Java. Util. Scanner;

Public class Main {
Public static void main (String [] args) {
Scanner Scanner=new Scanner (System. In);
String String=scanner. NextLine ();//input hexadecimal number
int sum=0;
for(int i=0; i{
Int m=string charAt (I);//the input hexadecimal string into individual characters
Int num=m>='A'? M - 'A' + 10: m - '0';//will turn numerical characters corresponding to the ASCII value of the
Sum +=math.h pow (16, string. The length () - 1 - I) * num.
}
System. The out. Println (sum);
}
}
can use c # write a [face] monkey2:002 PNG [/face]
  •  Tags:  
  • C#
  • Related