All hexadecimal conversions in hexadecimal notation !!!! Fast, simple operation, java, hexadecimal java

Source: Internet
Author: User

All hexadecimal conversions in hexadecimal notation !!!! Fast, simple operation, java, hexadecimal java

Import java. util. extends; public class P2031 {public static void main (String [] args) {Using SC = new using (System. in); char chs [] = {'0', '1', '2', '3', '4', '5', '6 ', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F '}; // The maximum number of all hexadecimal while (SC. hasNext () {int n = SC. nextInt (); // The number of int r = SC to be converted. nextInt (); // The hexadecimal boolean isNegative to be converted = false; // determines whether a negative number exists. if (n <0) {n =-n; isNegative = true ;} string str = ""; while (n/r> 0) {str = ch S [n % r] + str; // Add the calculated result to the front n = n/r;} if (n % r! = 0) {// if division is not allowed, run this operation and add the remainder to the beginning of the result str = chs [n % r] + str;} if (isNegative) {// run the command only when the plural number exists. Add the negative str = "-" + str;} System to the result. out. println (str );}}}

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.