exceptionaltest.java

来自「此文件名叫暑期」· Java 代码 · 共 27 行

JAVA
27
字号
import java.util.*;
public class ExceptionalTest {
  public static void main(String[] args){
	  int i=0;
	  int ntry = 1000000;
	  Stack s = new Stack();
	  long s1;
	  long s2;
	  System.out.println("Testing for empty stack");
	  s1 = new Date().getTime();
	  for(i = 0;i<ntry;i++)
		  if(!s.empty())s.pop();
	  s2=new Date().getTime();
	  System.out.println((s2-s1)+"millseconds");
	  System.out.println("catching the emptystackexception");
	  s1 = new Date().getTime();
	  for(i =0;i<ntry;i++){
		  try{
			  s.pop();
		  }
		  catch(EmptyStackException e){}
	  }
	  s2 = new Date().getTime();
	  System.out.println((s2-s1)+"millseconds");
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?