简体   繁体   English

如何在字符串中使用%?

[英]How do I use a % with a String?

I am new to Java trying to code a decimal to hexadecimal converter. 我是Java的新手,尝试将十进制转换为十六进制。 The converter almost works but the numbers are flipped so I need to fix that but it wont let me due to the code having Strings. 转换器几乎可以正常工作,但是数字被翻转了,所以我需要解决这个问题,但是由于包含Strings的代码,它不会让我失望。 Is there anyway to fix this or an easier way that I am missing? 无论如何,有没有解决这个问题的方法,或者我想念的更简单的方法?

Thank you. 谢谢。

  int temp, reverse;
  String digits = "0123456789ABCDEF";
  String hexa = " ";

  while (myDecimal > 0){
    int x = myDecimal % 16;
    hexa = hexa + digits.charAt(x);
    myDecimal = myDecimal / 16;
  }
  System.out.println(hexa);

  temp = hexa % 10;
  reverse = reverse * 10 + temp;
  hexa = hexa / 10;

hexa + digits.charAt(x)到-> digits.charAt(x)+ hexa

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM