@java Blue Bridge Cup Group B Exercise Basics (30) Question 10: Decimal turn hex
Keywords: circulating divisible remainder judgment
Resource constraints
Time limit: 1.0s Memory Limit: 512.0MB
Problem Description
Hexadecimal number in program design often use to represent a way of integers. It has 0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, F total of 16 symbols each represent 0 to 15 decimal. The method of counting is full hexadecimal 16 into one, the decimal number 16 is 10 in hexadecimal, decimal and hexadecimal 17 is 11, and so on, into sixteen decimal 30 system is 1E.
It is given a non-negative integer, which represents the hexadecimal form.
Input format
input comprises a non-negative integer a, represents a number to be converted. 0 <= a <= 2147483647
output format
outputs the hexadecimal representation of an integer
sample input
30
Sample Output
1E
Code:
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
if(n>=0&&n<=2147483647){
System.out.println(Integer.toHexString(n).toUpperCase());
}
}
}