about | help | code help+videos | done | prefs |
public boolean isDivisibleBy5andNOTby10(int n)
#1: public boolean isDivisibleBy5andNOTby10(int n) { boolean divBy5 = false; if (n % 5 == 0) { divBy5 = true; } boolean notDivBy10 = false; if (n % 10 != 0) { notDivBy10 = true; } boolean divBy5andNot10 = false; if (divBy5 && notDivBy10) { divBy5andNot10 = true; } return divBy5andNot10; } #2: public boolean isDivisibleBy5andNOTby10(int n) { boolean divBy5 = false; if (n % 5 == 0) { divBy5 = true; } boolean divBy10 = false; // !!!!! if (n % 10 == 0) { divBy10 = true; } boolean divBy5andNot10 = false; if (divBy5 && !divBy10) { // !!!!! divBy5andNot10 = true; } return divBy5andNot10; } isDivisibleBy5andNOTby10(5) → true isDivisibleBy5andNOTby10(10) → false isDivisibleBy5andNOTby10(15) → true ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 1
Copyright Nick Parlante 2017 - privacy