【开 Eclipse 版的999个理由 & 需要理由吗?】 http://community.csdn.net/Expert/topic/3472/3472604.xml?temp=.7752497
解决方案 »
- java的垃圾回收机制是完全不可控的,但调用System.gc()后不就会清理内存了吗
- JSP中是中文,传递到后台后是乱码!
- java中Jmenu的问题
- 通过正则表达式替换字符串报 java.lang.StackOverflowError
- 关于JAVA JDK API中的问题?
- 请教关于getByName方法的问题
- JSP,SERVLET~错误~谢谢
- 有没有跟JBuilder一样支持便捷EJB开发的开发工具吗?而且要内存占用小
- 经过这几天的观察,我觉得一个midlet里应该有如下这么几个线程,它和application是不一样的
- 谁能给我 Thinking in Java 2 简体中文 PDF版教材?
- 就是我有个mail收发程序,要求在windows,linux,unix上都能作为系统服务使用。就是说在用户登陆之前就在运行了,怎么做啊
- 关于ArrayList和Iterator的问题!(急!请高人们尽快给与答复...)
char[] c=str.toCharArray();
for(int i=0;i<c.length;i++){
if(c[i]!='0'){
System.out.println(i+1);
break;
}
char[] c=str.toCharArray();
for(int i=0;i<c.length;i++){
if(c[i]=='1'){
System.out.println("u get it!");
break;
}else{ continue; }
}
不过我要问的就是位操作
谁写一个完整的Demo,ok?
包括边界问题,异常,等等
public static void main(String[] args) {
byte n = (byte) new Random().nextInt(256);
int r = 0x100;
int index = -1; for (int i = 0; i < 8; ++i) {
r >>>= 1;
if ((n & r) == 0) {
index = i;
break;
}
} StringBuffer s = new StringBuffer(8);
s.append(Integer.toBinaryString(n & 0xFF));
int l = 8 - s.length();
for (int i = 0; i < l; ++i) {
s.insert(0, '0');
}
System.out.println("n = " + s.toString() + ", index = " + index);
}
}
n = 10000001, index = 1
n = 00011000, index = 0
n = 11111001, index = 5
n = 00110000, index = 0
n = 01011110, index = 0
n = 10110011, index = 1
n = 01110010, index = 0
n = 11111100, index = 6
n = 00100110, index = 0
<当是从右到左找第一个不为0的位置>public class Demo
{
public static int aa() {
byte b = 55;
if (b < 0) return 1;
if ((b & 64) == 64) return 2;
if ((b & 32) == 32) return 3;
if ((b & 16) == 16) return 4;
if ((b & 8) == 128) return 5;
if ((b & 4) == 4) return 6;
if ((b & 2) == 2) return 7;
if ((b & 1) == 1) return 8;
return 0;
}
public static void main(String[] args) {
System.out.println(aa());
}
}大致意思是这样,算法可自己优化一下