为怎么我注释的这段代码yu不减0的时候(或者为怎么yu还要加一个0),打印出来会报错,为怎么前面还要加个'0'?
程序代码:
import java.util.Scanner; public class Case17 { public static void main(String [] args){ Scanner in = new Scanner (System.in); System.out.println("请输入number的十进制数"); int number = in.nextInt(); int shang = number; String tex = ""; int yu; while(shang!=0){ yu = shang%16; shang = shang/16; char result; if(yu<9){ result = (char)('0'+(yu-0));//为怎么我注释的这段代码yu不减0的时候,打印出来会报错,为怎么前面还要加个'0'? }else{ result = (char)('A'+(yu-10)); } tex = result + tex; } System.out.println(number+"的十六进制形式是:"+tex); } }
result = (char)('0'+(yu));yu不减零的时候运行结果