【发布时间】:2015-09-29 20:16:40
【问题描述】:
byte[] stuffA = {69,96,13,37,-69,-96,-13,-37};
for(int x = 0; x < stuffA.length; x++){
if(stuffA[x] < 0){
System.out.println("Somethin be up yo! ");
System.out.println("This number be negative! " + (int)stuffA[x]);
stuffA[x] = (byte)((int)stuffA[x] + 256);
System.out.println("I added 256 and now stuff is positive yo! " + stuffA[x]);
}
}
return;
当我运行它时,我的输出是:
Somethin be up yo!
This number be negative! -69
I added 256 and now stuff is positive yo! -69
Somethin be up yo!
This number be negative! -96
I added 256 and now stuff is positive yo! -96
Somethin be up yo!
This number be negative! -13
I added 256 and now stuff is positive yo! -13
Somethin be up yo!
This number be negative! -37
I added 256 and now stuff is positive yo! -37
发生了什么?
【问题讨论】:
-
你认为一个字节可以存储的值的范围是多少?