//李白饮酒问题 public class Wire { public static void main(String[] args) { // 反推,最后一次遇花店 double end = 0; // 倒数第二次为 end = end + 1; for (int i = 0; i < 5; i++) { // 前9次为随机 // Random ran = new Random(); // System.out.println(ran.nextBoolean()); end /= 2; end++; } System.out.println(end); } } 打印答案:1.96875 但是始终觉得有点问题.
把用C++写好的打包封装成动态库.dll文件, 在java中调用例如: public class GetData { public native String GetSerial(String S1); //用native 说明后面的方法是其 它语言的方法,加载到本地方法,后面可以直接用 public native String GetIP(String S1); public native String GetMAC(String S1); public native String GetCorp(String S1); public native byte[] baGetCorp(String S1);
C++还需要包装一套JNI的适配器
public class Wire {
public static void main(String[] args) {
// 反推,最后一次遇花店
double end = 0;
// 倒数第二次为
end = end + 1;
for (int i = 0; i < 5; i++) {
// 前9次为随机
// Random ran = new Random();
// System.out.println(ran.nextBoolean());
end /= 2;
end++;
}
System.out.println(end);
}
}
打印答案:1.96875
但是始终觉得有点问题.
public class GetData {
public native String GetSerial(String S1); //用native 说明后面的方法是其 它语言的方法,加载到本地方法,后面可以直接用
public native String GetIP(String S1);
public native String GetMAC(String S1);
public native String GetCorp(String S1);
public native byte[] baGetCorp(String S1);
static {
System.loadLibrary("Antiscan"); //Antiscan c++的DLL文件名
}
public String getcorp(String S1) {
String bS = null;
byte ba[] = baGetCorp(S1); //这里调用dll里的方法
if (ba != null) {
bS = new String(ba);
}
return bS;
}
}
发现一个比jni更方便的方法就是用jni基础之上的一个开源工具包jnative,非常方便的。