当我尝试将 2 个 int 值相乘时,我不知道为什么此代码片段会产生以下输出。这可能太愚蠢了,但我就是不明白。我在这里粘贴了代码和输出
public static void main(String[] args) {
// TODO code application logic here
String numstring = "12122";
char[] numArray = numstring.toCharArray();
int num =0;
int index = 10;
int count = 0;
for(int i=numArray.length-1;i>=0;i--){
int ind = (int)(Math.pow(index,count));
System.out.print(numArray[i]+"*"+ind);
System.out.println(" prints as ----->"+numArray[i]*ind);
count++;
}
}
输出:
2*1 prints as ----->50
2*10 prints as ----->500
1*100 prints as ----->4900
2*1000 prints as ----->50000
1*10000 prints as ----->490000