现在的位置: 首页 > 综合 > 正文

java—try —catch–finally

2013年10月10日 ⁄ 综合 ⁄ 共 464字 ⁄ 字号 评论关闭
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);
  }
 }
}

 

抱歉!评论已关闭.