Upload files to "OOP/Java/Lab/Week10"
This commit is contained in:
parent
2b9a21ac62
commit
22f306573d
5 changed files with 160 additions and 0 deletions
23
OOP/Java/Lab/Week10/EvenNumberHandling.java
Normal file
23
OOP/Java/Lab/Week10/EvenNumberHandling.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
class EvenNumberException extends Exception{
|
||||
EvenNumberException(String message){
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
public class EvenNumberHandling {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("Enter a number");
|
||||
try{
|
||||
int input = sc.nextInt();
|
||||
if(input%2==0){
|
||||
throw new EvenNumberException("You had to enter an odd number");
|
||||
}
|
||||
System.out.println("Odd number was entered");
|
||||
}catch(EvenNumberException e){
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue