Android - How to simplify multiple of ten?
I want to multiple values like this:
if (currentScore == 10 | currentScore == 20 | currentScore == 30 | currentScore == 40 | currentScore == 50 | currentScore == 60
| currentScore == 70 | currentScore == 80 | currentScore == 90 | currentScore == 100 | currentScore == 110
| currentScore == 120 | currentScore == 130 | currentScore == 140 | currentScore == 150 | currentScore == 160
| currentScore == 170 | currentScore == 180 | currentScore == 190 | currentScore == 200) {
editor.putInt("TOP_LEVEL", topLevel + 1);
editor.apply();
}
How to simplify that code so can count many currentScore.
Thanks
add a comment |
I want to multiple values like this:
if (currentScore == 10 | currentScore == 20 | currentScore == 30 | currentScore == 40 | currentScore == 50 | currentScore == 60
| currentScore == 70 | currentScore == 80 | currentScore == 90 | currentScore == 100 | currentScore == 110
| currentScore == 120 | currentScore == 130 | currentScore == 140 | currentScore == 150 | currentScore == 160
| currentScore == 170 | currentScore == 180 | currentScore == 190 | currentScore == 200) {
editor.putInt("TOP_LEVEL", topLevel + 1);
editor.apply();
}
How to simplify that code so can count many currentScore.
Thanks
add a comment |
I want to multiple values like this:
if (currentScore == 10 | currentScore == 20 | currentScore == 30 | currentScore == 40 | currentScore == 50 | currentScore == 60
| currentScore == 70 | currentScore == 80 | currentScore == 90 | currentScore == 100 | currentScore == 110
| currentScore == 120 | currentScore == 130 | currentScore == 140 | currentScore == 150 | currentScore == 160
| currentScore == 170 | currentScore == 180 | currentScore == 190 | currentScore == 200) {
editor.putInt("TOP_LEVEL", topLevel + 1);
editor.apply();
}
How to simplify that code so can count many currentScore.
Thanks
I want to multiple values like this:
if (currentScore == 10 | currentScore == 20 | currentScore == 30 | currentScore == 40 | currentScore == 50 | currentScore == 60
| currentScore == 70 | currentScore == 80 | currentScore == 90 | currentScore == 100 | currentScore == 110
| currentScore == 120 | currentScore == 130 | currentScore == 140 | currentScore == 150 | currentScore == 160
| currentScore == 170 | currentScore == 180 | currentScore == 190 | currentScore == 200) {
editor.putInt("TOP_LEVEL", topLevel + 1);
editor.apply();
}
How to simplify that code so can count many currentScore.
Thanks
asked Nov 24 '18 at 2:57
Bonnie7Bonnie7
1216
1216
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Use the Java % operator:
if (currentScore % 10 == 0) {
editor.putInt("TOP_LEVEL", topLevel + 1);
editor.apply();
}
The % operator returns a remainder. If the remainder of the division of "currentScore" by 10 is 0, this means that currentScore is an exact multiple of 10.
1
Okay, I will test your code. Please wait bro
– Bonnie7
Nov 24 '18 at 4:03
add a comment |
int j = 10;
for (int i = 1; i <= 20 ; i++) {
if (currentScore == j) {
editor.putInt("TOP_LEVEL", topLevel + 1);
editor.apply();
break;
}
j = j + 10;
}
This will not work for any other number than currentScore being 10, e.g. if currentScore = 100, your program will not work. And even then, why are you printing 20 times?
– vs97
Nov 24 '18 at 3:32
I edited my answer, now it works fine :) thank you @vshcherbinin
– Mester Hassan
Nov 24 '18 at 4:00
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454790%2fandroid-how-to-simplify-multiple-of-ten%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use the Java % operator:
if (currentScore % 10 == 0) {
editor.putInt("TOP_LEVEL", topLevel + 1);
editor.apply();
}
The % operator returns a remainder. If the remainder of the division of "currentScore" by 10 is 0, this means that currentScore is an exact multiple of 10.
1
Okay, I will test your code. Please wait bro
– Bonnie7
Nov 24 '18 at 4:03
add a comment |
Use the Java % operator:
if (currentScore % 10 == 0) {
editor.putInt("TOP_LEVEL", topLevel + 1);
editor.apply();
}
The % operator returns a remainder. If the remainder of the division of "currentScore" by 10 is 0, this means that currentScore is an exact multiple of 10.
1
Okay, I will test your code. Please wait bro
– Bonnie7
Nov 24 '18 at 4:03
add a comment |
Use the Java % operator:
if (currentScore % 10 == 0) {
editor.putInt("TOP_LEVEL", topLevel + 1);
editor.apply();
}
The % operator returns a remainder. If the remainder of the division of "currentScore" by 10 is 0, this means that currentScore is an exact multiple of 10.
Use the Java % operator:
if (currentScore % 10 == 0) {
editor.putInt("TOP_LEVEL", topLevel + 1);
editor.apply();
}
The % operator returns a remainder. If the remainder of the division of "currentScore" by 10 is 0, this means that currentScore is an exact multiple of 10.
edited Nov 24 '18 at 3:22
answered Nov 24 '18 at 3:01
vs97vs97
449217
449217
1
Okay, I will test your code. Please wait bro
– Bonnie7
Nov 24 '18 at 4:03
add a comment |
1
Okay, I will test your code. Please wait bro
– Bonnie7
Nov 24 '18 at 4:03
1
1
Okay, I will test your code. Please wait bro
– Bonnie7
Nov 24 '18 at 4:03
Okay, I will test your code. Please wait bro
– Bonnie7
Nov 24 '18 at 4:03
add a comment |
int j = 10;
for (int i = 1; i <= 20 ; i++) {
if (currentScore == j) {
editor.putInt("TOP_LEVEL", topLevel + 1);
editor.apply();
break;
}
j = j + 10;
}
This will not work for any other number than currentScore being 10, e.g. if currentScore = 100, your program will not work. And even then, why are you printing 20 times?
– vs97
Nov 24 '18 at 3:32
I edited my answer, now it works fine :) thank you @vshcherbinin
– Mester Hassan
Nov 24 '18 at 4:00
add a comment |
int j = 10;
for (int i = 1; i <= 20 ; i++) {
if (currentScore == j) {
editor.putInt("TOP_LEVEL", topLevel + 1);
editor.apply();
break;
}
j = j + 10;
}
This will not work for any other number than currentScore being 10, e.g. if currentScore = 100, your program will not work. And even then, why are you printing 20 times?
– vs97
Nov 24 '18 at 3:32
I edited my answer, now it works fine :) thank you @vshcherbinin
– Mester Hassan
Nov 24 '18 at 4:00
add a comment |
int j = 10;
for (int i = 1; i <= 20 ; i++) {
if (currentScore == j) {
editor.putInt("TOP_LEVEL", topLevel + 1);
editor.apply();
break;
}
j = j + 10;
}
int j = 10;
for (int i = 1; i <= 20 ; i++) {
if (currentScore == j) {
editor.putInt("TOP_LEVEL", topLevel + 1);
editor.apply();
break;
}
j = j + 10;
}
edited Nov 24 '18 at 3:58
answered Nov 24 '18 at 3:21
Mester HassanMester Hassan
15019
15019
This will not work for any other number than currentScore being 10, e.g. if currentScore = 100, your program will not work. And even then, why are you printing 20 times?
– vs97
Nov 24 '18 at 3:32
I edited my answer, now it works fine :) thank you @vshcherbinin
– Mester Hassan
Nov 24 '18 at 4:00
add a comment |
This will not work for any other number than currentScore being 10, e.g. if currentScore = 100, your program will not work. And even then, why are you printing 20 times?
– vs97
Nov 24 '18 at 3:32
I edited my answer, now it works fine :) thank you @vshcherbinin
– Mester Hassan
Nov 24 '18 at 4:00
This will not work for any other number than currentScore being 10, e.g. if currentScore = 100, your program will not work. And even then, why are you printing 20 times?
– vs97
Nov 24 '18 at 3:32
This will not work for any other number than currentScore being 10, e.g. if currentScore = 100, your program will not work. And even then, why are you printing 20 times?
– vs97
Nov 24 '18 at 3:32
I edited my answer, now it works fine :) thank you @vshcherbinin
– Mester Hassan
Nov 24 '18 at 4:00
I edited my answer, now it works fine :) thank you @vshcherbinin
– Mester Hassan
Nov 24 '18 at 4:00
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454790%2fandroid-how-to-simplify-multiple-of-ten%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown