TestArray

这篇博客通过一个名为'Count3Quit'的例子,详细探讨了数组在编程中的使用,包括元素计数、条件判断等操作。内容适合初学者理解和实践。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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);
	}

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值