您的位置:首页 > 编程语言 > Java开发

java---try ---catch--finally

2012-11-23 23:57 661 查看
package hello;

import java.io.IOException;

public class hello {
 int count = 0;
 public void check() throws IOException {
  byte[] str = new byte[20];
  System.in.read(str);
  for (int i = 0; i < str.length - 1; i++)
  {
   if (str[i] == 'Z') {
    count++; 
   }
  }
  if(count>0)
  {
   throw new IOException("按下了Z键");
  }

 }
  public static void main(String args[])
  {
   hello ts =new  hello();
  System.out.println("请输入你想输入的字符串:");
 
   try {
    ts.check();
    return;
   }  catch (IOException ie) {
    ie.printStackTrace();
   }finally {
   System.out.println("z is ");
   System.out.print(ts.count);
  }
 }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: