public class Split{
public static void main(String[] args){
double pai = 3.14159;
findTwo(pai);
public static void findTwo(double value){
System.out.println(new DecimalFormat("0.##").format(value));
}
}
} ......
package arrays.compara;
/**
*
* @author Happy 二分查找法
*/
public class BinarySearch {
public static void main(String[] args) {
int[] arrInt = { 2, 34, 32, 24, 23, 34, 12, 3, 4, 2 };
int index = bSearch(29, arrInt, 0, arrInt.length);
System.out.println("Index : " + index);
/*
* for (int i : arrInt) { System.out.println(i); }
*/
}
// js二分查找法(没有成功)
private static int bSerarch(int[] arrInt, int value) {
int startIndex = 0, stopIndex = arrInt.length - 1, middle = (int) (Math
.floor((stopIndex + startIndex) / 2));
while (arrInt[middle] != value && startIndex < stopIndex) {
// adjust search area(调整查找范围)
if (value < arrInt[middle]) {
stopIndex = middle - 1;
} else if (value > arrInt[middle]) {
& ......
package arrays.compara;
import java.util.Arrays;
public class Student {
public static void main(String[] args) {
Stu[] stus = new Stu[]{
new Stu(156,34,"ad"),
new Stu(153,24,"cc"),
new Stu(126,37,"ab"),
new Stu(176,45,"as"),
new Stu(156,34,"bd")
};
Arrays.sort(stus);
for (int i = 0; i < stus.length; i++) {
System.out.println(stus[i].toString());
}
}
}
class Stu implements Comparable<Object> {
int hight;
int age;
String name;
public Stu(int hight, int age, String name) {
this.hight = hight;
this.age = age;
this.name = name;
}
//年龄比较
/*public int compareTo(Object obj) {
return (this.age > ((Stu)obj).age) ? 1 : (this.age == ((Stu)obj).age) ? 0 : -1;
......
package arrays.file;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Random;
public class ConcludeCombinationSortWrite {
/**
* 大数据排序合并
*
* @param args
*/
public static void main(String[] args) throws IOException {
// 写入文件的路径
String filePath = "D:\\456";
// 切分文件的路径
String sqlitFilePath = "D:\\456\\123";
//数据的个数
int CountNumbers=10000000;
//子文件的个数
int CountFile=10;
//精度
int countAccuracy=30*CountFile;
long startNumber=System.currentTimeMillis();
// 写入大数据文件
......
package arrays.file;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.Writer;
public class CreateFile {
public static void main(String[] args) {
// readerFile("E:/workspace6/Arrays/src/myArray/Nodes.java");
// readerFileToo();
//writeInMemroy();
writeFile2();
}
// 经典读取数据一
public static String readerFile() {
// E:/workspace6/Arrays/src/myArray/Nodes.java
String s, s2 = "";
try {
BufferedReader in = new BufferedReader(new FileReader
("E:/workspace6/Arrays/src/myArray/Nodes.java"));
try {
&nb ......
package arrays.myArray;
public class BinaryTree {
private Node root;
// 添加数据
public void add(int data) {
// 递归调用
if (null == root)
root = new Node(data, null, null);
else
addTree(root, data);
}
private void addTree(Node rootNode, int data) {
// 添加到左边
if (rootNode.data > data) {
if (rootNode.left == null)
rootNode.left = new Node(data, null, null);
else
addTree(rootNode.left, data);
} else {
// 添加到右边
if (rootNode.right == null)
rootNode.right = new Node(data, null, null);
else
addTree(rootNode.right, data);
}
}
// 查询数据
public void show() {
showTree(root);
}
priv ......