java中的foreach用法
import java.util.*;
public class ForeachExample {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Random r = new Random();
int[] x = new int[10];
for (int i = 0; i < x.length; i++) {
x[i] = r.nextInt(100);
}
// foreach的使用
for (int y : x) {
System.out.print(y + " ");
}
System.out.println();
// 另一种打印数组的方式
System.out.println(Arrays.toString(x));
for (char c : "I am a good girl!".toCharArray())
System.out.print(c + " ");
}
}
相关文档:
//静态块(static block):如下所示
public class StaticBlock1
{
static
{
System.out.println("static block");
......
2009-11-11 18:06:09
/**
*
* @author Ice*
*/
public class RarUtil{
public static void main(String args[]) throws Exception {
String compress = "D:\\test.rar";// rar压缩文件
String decompression = "D:\\";// 解压路径
unZip(compress, decompression);
}
/** ......
先看个例子:
接口
package example;
public interface Basic {
public void hello();
}
接口的实现类
package example;
public class BasicService implements Basic {
public void hello() {
Sysyt ......