Java的求质数
package stone;
public class PrimerNumber {
public static void main(String[] args) {
int MAX_NUMBER = 100;
boolean[] notPrimer= new boolean[MAX_NUMBER];
for(int i=2;i<=MAX_NUMBER;i++){
if(!notPrimer[i-1]){
for(int j=2*i;j<=MAX_NUMBER;j++){
if(j%i==0) notPrimer[j-1]=true;
}
}
}
for(int i=0;i<MAX_NUMBER;i++){
if(!notPrimer[i]) System.out.print(i+1+" ");
}
}
}
运行结果如下:
1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
相关文档:
获得mysql和oracle链接的类
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectDB {
private static final String MYSQL = "jdbc:mysql://";
private static final String ORACLE = "jdbc:oracle:thin:@";
private ConnectD ......
/**
* Copyright (c) 2010 IBOBO Corporation. All Rights Reserved.
*/
package com.ibm.util.dao.hib;
/**
* [Java Generics] get T.Class from <T>
*
* @author <a ......
/*
* GetMacAddress .java
*
* description:get Mac addreess
*
* @author hadeslee
*
* Created on 2007-9-27, 9:11:15
*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package test2;
import java.io.BufferedReader;
import java.io.IO ......
判断一个文件是否为二进制文件
public static boolean isBinary(File file) {
boolean isBinary = false;
try {
FileInputStream fin = new FileInputStream(file);
long len = file.length();
for (int j = 0; j < (int) len; j++) {
int t = fin.read();
......