Skip to content

Instantly share code, notes, and snippets.

@eroltutumlu
Last active August 29, 2015 14:15
Show Gist options
  • Save eroltutumlu/b418697c44ac95720ddb to your computer and use it in GitHub Desktop.
Save eroltutumlu/b418697c44ac95720ddb to your computer and use it in GitHub Desktop.
Exception
package Sample;
public class Main {
public static void main(String[] args) {
Divide exp = new Divide();
int Sonuc = exp.Divider(10, 5);
if(exp.getErrorFlag())
{
System.out.println(exp.ErrorMessage());
}
else
{
System.out.println(Sonuc);
}
}
}
class Divide {
//@Data encapsulation Access modifier
private boolean ErrorFlag;
private String ErrorMessage;
//@Getter
public boolean getErrorFlag()
{
return ErrorFlag;
}
//@Getter
public String getErrorMessage()
{
return ErrorMessage;
}
public int Divider(int a, int b)
{
if(a < 0 || b < 0)
{
this.ErrorFlag = true;
this.ErrorMessage = "Negatif değer girilemez.";
return 0;
}
if(b==0)
return 0;
else
return a/b;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment