Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.lang.Exception;
- class CustomException extends Exception{
- public CustomException(String err){
- super(err);
- }
- }
- class Equation {
- float a, b = 0;
- public Equation(float a, float b) {
- this.a = a;
- this.b = b;
- }
- public float Resolve() throws CustomException{
- if (a == 0 && b == 0){
- throw (new CustomException("solution tout R"));
- }
- else if (a == 0 || b == 0){
- throw (new CustomException("impossible"));
- }
- else{
- return (-(b/a));
- }
- }
- }
- public class Main {
- public static void main(String[] args) throws CustomException {
- Equation eq = new Equation(0,0);
- System.out.println(eq.Resolve());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement