/**
* 产生一个-100到100以内的随机数,判断这个随机数是不是偶数
* @author Administrator
*
*/
class NotPlus extends Exception{
public String notPlus(){
String name="随机数不是正数";
System.out.println(name);
return name;
}
}
class NotEven extends Exception{
public String notEven(){
String name="随机数不是偶数";
System.out.println(name);
return name;
}
}
public class TestException {
public void countNumber(int number)throws NotPlus,NotEven{
if(number<0){
NotPlus np=new NotPlus();
np.notPlus();
}
else if(number%2!=0){
NotEven ne=new NotEven();
ne.notEven();
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TestException testException=new TestException();
int number=(int)(Math.random()*100);
double temp=Math.random();
if(temp<0.5){
number=-number;
}
System.out.println("temp="+temp);
System.out.println("产生的随机数是"+number);
try{
testException.countNumber(number);
}
catch (NotPlus e) {
e.notPlus();
}
catch (NotEven e) {
e.notEven();
}
}
}
Smilar Posts of About JAVA custom exceptions
-
Build flex + spring + blazeds + hibernate application
Build flex + spring + blazeds + hibernate application First, set up the project blazeds 1, will blazeds.war extract to a directory, such as: myflex /; 2, set up java works were such as: MyFlex, in the ...
-
Hibernate connection pool configuration
Hibernate connection pool configuration oracle.jdbc.driver.OracleDriver jdbc: oracle: thin: @ 10.203.14.132:1521: remotedb
-
hibernate generic generic DAO
hibernate generic generic DAO
-
First Hibernate Example
Curd a simple example. Source does not contain the dependent libraries, or playing too much of the package. PO object Note: One must have the default constructor 2 non-final modified. Otherwise useles ...
-
Struts2 + hibernate + spring problem user log in
dao layer services layer action jsp user name: Password:
-
Hibernate secondary cache
Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml ...
-
The level Hibernate cache
Hibernate cache level: (1) a cache is very short and the session life cycle consistent, also known as session-level cache-level cache or transaction-level cache (2) Ways of Supporting level cache: get ...
-
Hibernate's lazy strategy
hibernate Lazy strategy can be used in: tag, it can be true / false Tags can values true / false type of necessary tools to enhance can tag values true / false / extra can be single-ended cor ...







