Blue Bridge cup of java basic exercises decimal convert hexadecimal

Basic exercises decimal convert hexadecimal

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 contains a non-negative integer a, represents a number to be converted. 0 <= a <= 2147483647

Output Format

The output of this integer hexadecimal

Sample input

30

Sample Output

1E

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {        
        Scanner scanner=new Scanner(System.in);
        int number=scanner.nextInt();
        String str=Integer.toHexString(number);
        System.out.println(str.toUpperCase());
    }
}
Published 24 original articles · won praise 2 · Views 194

Guess you like

Origin blog.csdn.net/weixin_44570019/article/details/104515365