Count3Quit
package com.infy.tests;
public class Count3Quit {
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean[] arr = new boolean[500];
for (int i = 0; i < arr.length; i++) {
arr[i] = true;
}
int leftCount = arr.length;
int index = 0;
int countNum = 0;
while (leftCount > 1) {
if (arr[index] == true) {
countNum++;
if (countNum == 3) {
arr[index] = false;
countNum = 0;
leftCount--;
}
}
index++;
if (index == arr.length) {
index=0;
}
}
for (int i = 0; i< arr.length; i++){
if (arr[i]==true){
System.out.print(i);
}
}
}
}
TestThread
package com.infy.tests;
import java.lang.*;
public class TestThread {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
// public enum Myclolor {red,yellow,blue};
Runner1 r = new Runner1();
Thread t = new Thread(r);
t.start();
// Thread.sleep(1000);
for (int i=0; i<100; i++) {
System.out.println("main thread----------:" + i);
}
}
}
package com.infy.tests;
public class Runner1 implements Runnable {
// public enum Mycolor {red,blue,gree};
@Override
public void run() {
// TODO Auto-generated method stub
for (int i =0; i<100; i++) {
System.out.println("Runner1:" + i);
}
}
}
TestArray
package com.infy.tests;
//import java.awt.print.Printable;
public class TestArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] a= new int[args.length];
for (int i = 0; i < args.length; i++) {
a[i] = Integer.parseInt(args[i]);
}
print(a);
System.out.println(" ");
selectSort(a);
print(a);
/*
for (int i=0; i<args.length; i++){
System.out.println(args[i]);
}
*/
/*
if (args.length < 3 || args.length >3 ){
System.out.println("usage: Java Test \"n1\" \"op\" \"n2\"");
System.exit(-1);
}
double d1=Double.parseDouble(args[0]);
double d2=Double.parseDouble(args[2]);
double d3 = 0;
if (args[1].equals("+")) {
d3 = d1 + d2;
} else if (args[1].equals("-")) {
d3 = d1 - d2;
} else if (args[1].equals("x")) {
d3= d1 * d2;
} else if (args[1].equals("/")) {
d3= d1 / d2;
} else {
System.out.print("Error operation");
System.exit(-1);
}
System.out.println(d3);
*/
}
private static void print(int[] a){
for (int i =0; i< a.length; i++){
System.out.print(a[i]+" ");
}
}
private static void selectSort(int[] a){
for (int i=0; i<a.length;i++){
for (int j=i+1; j<a.length;j++)
if (a[i]>a[j]){
int temp= a[i];
a[i]=a[j];
a[j]= temp;
}
//System.out.print(a[i]);
}
}
}
TestArrayList
package com.infy.tests;
import java.util.*;
public class TestArrayList {
public static void main(String[] args) {
// TODO Auto-generated method stub
/*
ArrayList l1 = new ArrayList();
for (int i=0; i<= 5; i++){
l1.add("a"+ i);
}
System.out.println(l1);
l1.add(3,100);
System.out.println(l1);
l1.set(5, "a300");
System.out.println(l1);
*/
List l2 = new LinkedList();
for (int i=0; i<=9; i++){
l2.add("a"+ i);
}
System.out.println(l2);
Collections.shuffle(l2);
System.out.println(l2);
Collections.sort(l2);
System.out.println(l2);
}
}
TestList
package com.infy.tests;
import java.io.*;
public class TestList {
public static void main(String[] args) {
// TODO Auto-generated method stub
File f = new File("d:/A");
System.out.println(f.getName());
tree(f,1);
}
public static void tree(File f, int level) {
String preStr = "";
for (int i=0; i<level; i++){
preStr +=" ";
}
File[] childs = f.listFiles();
for (int i = 0; i < childs.length; i++) {
System.out.println(preStr + childs[i].getName());
if (childs[i].isDirectory()){
tree(childs[i],level+1);
}
}
}
}
TestMap
package com.infy.tests;
import java.util.*;
public class TestMap {
public static void main(String[] args) {
// TODO Auto-generated method stub
Map m1 = new HashMap();
//m1.put("One", new Integer(1));
m1.put("One", 1);
//m1.put("Two", new Integer(2));
m1.put("Two", 2);
//m1.put("Three", new Integer(3));
m1.put("Three", 3);
System.out.println(m1.size());
if(m1.containsKey("Two")){
int i = (Integer)m1.get("Two");
System.out.println(i);
}
}
}
TestName
package com.infy.tests;
import java.util.Collections;
import java.util.LinkedList;
public class TestName {
public static void main(String[] args) {
// TODO Auto-generated method stub
LinkedList<Name> l1 = new LinkedList();
l1.add(new Name("george", "liu"));
l1.add(new Name("george","shanghai"));
System.out.println(l1);
l1.add(new Name("vivian", "wang"));
l1.add(new Name("jashon", "chen"));
Collections.sort(l1);
System.out.print(l1);
}
}
/*
[com.infy.tests.Name@1cfb549]
[com.infy.tests.Name@1cfb549, com.infy.tests.Name@1fae3c6, com.infy.tests.Name@7ffe01]
*/
TestSet
package com.infy.tests;
import java.util.*;
public class TestSet {
public static void main(String[] args) {
// TODO Auto-generated method stub
HashSet s = new HashSet();
s.add("hello");
s.add("world");
s.add(new Integer(100));
s.add("hello");
HashSet s1 = new HashSet(s);
s1.add("nihao");
HashSet sn = new HashSet();
sn.addAll(s1);
System.out.println(sn);
}
}