Skip to content

Instantly share code, notes, and snippets.

@dickygiancini
Last active February 5, 2021 08:56
Show Gist options
  • Save dickygiancini/bb0f20324d248cb65715b76c769766b4 to your computer and use it in GitHub Desktop.
Save dickygiancini/bb0f20324d248cb65715b76c769766b4 to your computer and use it in GitHub Desktop.
My first actual dart only program after doing some Flutter. It's an ablation so you prob don't know much
int below50(int a, int b){
int calc = a + b;
return calc;
}
List somePlanet() => ["Merc", "Ven", "Earth"];
String scoreChecker(int c, int d){
int testDivide = below50(c,d) ~/ 2;
print(testDivide);
if (testDivide < 50){
return "below 50";
}
else {
return "above 50";
}
}
int divideZero(int x){
return x ~/ 0;
}
class DivideExceptions implements Exception{
String errormsg(){
return "you cannot ngutang";
}
}
void ngutang(int amount){
if (amount < 0){
throw new DivideExceptions();
}
else {
print("gak ngutang");
}
}
void main() {
var score1 = 66;
var score2 = 23;
var printScore = scoreChecker(score1,score2);
print(printScore);
for (String myPlanet in somePlanet()){
if (myPlanet == "Earth"){
break;
}
else {
print(myPlanet);
}
}
try {
divideZero(2);
}
catch(e){
print("The exception thrown is $e");
}
try {
ngutang(200);
}
catch(e){
print(e.errormsg());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment