stuck with this while loop java [closed]












-1














I have been working with while loops however I cant seem to understand how the remainder works inside this code.



int a = 10;
while( a <= 1000 && a % 100 != 0){
System.out.println("a = " + a);
a = a + 10;
}









share|improve this question















closed as unclear what you're asking by Sotirios Delimanolis, talex, CozyAzure, EdChum, Unheilig Nov 23 '18 at 9:34


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 1




    doubt that compiles.
    – Aomine
    Nov 22 '18 at 23:28






  • 1




    is it just me who doesn't understand what the OP means by remainder here?
    – Kartik
    Nov 22 '18 at 23:32










  • Could it be that you mixed up bitwise and operator & and remainder operator %?
    – Michael Butscher
    Nov 22 '18 at 23:34










  • @MichaelButscher that explains it. The code works after replacing & with %.
    – Kartik
    Nov 22 '18 at 23:39










  • sorry, there is a type in a & 100 != 0 the & should be %
    – M4rss
    Nov 23 '18 at 0:41
















-1














I have been working with while loops however I cant seem to understand how the remainder works inside this code.



int a = 10;
while( a <= 1000 && a % 100 != 0){
System.out.println("a = " + a);
a = a + 10;
}









share|improve this question















closed as unclear what you're asking by Sotirios Delimanolis, talex, CozyAzure, EdChum, Unheilig Nov 23 '18 at 9:34


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 1




    doubt that compiles.
    – Aomine
    Nov 22 '18 at 23:28






  • 1




    is it just me who doesn't understand what the OP means by remainder here?
    – Kartik
    Nov 22 '18 at 23:32










  • Could it be that you mixed up bitwise and operator & and remainder operator %?
    – Michael Butscher
    Nov 22 '18 at 23:34










  • @MichaelButscher that explains it. The code works after replacing & with %.
    – Kartik
    Nov 22 '18 at 23:39










  • sorry, there is a type in a & 100 != 0 the & should be %
    – M4rss
    Nov 23 '18 at 0:41














-1












-1








-1







I have been working with while loops however I cant seem to understand how the remainder works inside this code.



int a = 10;
while( a <= 1000 && a % 100 != 0){
System.out.println("a = " + a);
a = a + 10;
}









share|improve this question















I have been working with while loops however I cant seem to understand how the remainder works inside this code.



int a = 10;
while( a <= 1000 && a % 100 != 0){
System.out.println("a = " + a);
a = a + 10;
}






java






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 0:43

























asked Nov 22 '18 at 23:26









M4rss

121




121




closed as unclear what you're asking by Sotirios Delimanolis, talex, CozyAzure, EdChum, Unheilig Nov 23 '18 at 9:34


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by Sotirios Delimanolis, talex, CozyAzure, EdChum, Unheilig Nov 23 '18 at 9:34


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 1




    doubt that compiles.
    – Aomine
    Nov 22 '18 at 23:28






  • 1




    is it just me who doesn't understand what the OP means by remainder here?
    – Kartik
    Nov 22 '18 at 23:32










  • Could it be that you mixed up bitwise and operator & and remainder operator %?
    – Michael Butscher
    Nov 22 '18 at 23:34










  • @MichaelButscher that explains it. The code works after replacing & with %.
    – Kartik
    Nov 22 '18 at 23:39










  • sorry, there is a type in a & 100 != 0 the & should be %
    – M4rss
    Nov 23 '18 at 0:41














  • 1




    doubt that compiles.
    – Aomine
    Nov 22 '18 at 23:28






  • 1




    is it just me who doesn't understand what the OP means by remainder here?
    – Kartik
    Nov 22 '18 at 23:32










  • Could it be that you mixed up bitwise and operator & and remainder operator %?
    – Michael Butscher
    Nov 22 '18 at 23:34










  • @MichaelButscher that explains it. The code works after replacing & with %.
    – Kartik
    Nov 22 '18 at 23:39










  • sorry, there is a type in a & 100 != 0 the & should be %
    – M4rss
    Nov 23 '18 at 0:41








1




1




doubt that compiles.
– Aomine
Nov 22 '18 at 23:28




doubt that compiles.
– Aomine
Nov 22 '18 at 23:28




1




1




is it just me who doesn't understand what the OP means by remainder here?
– Kartik
Nov 22 '18 at 23:32




is it just me who doesn't understand what the OP means by remainder here?
– Kartik
Nov 22 '18 at 23:32












Could it be that you mixed up bitwise and operator & and remainder operator %?
– Michael Butscher
Nov 22 '18 at 23:34




Could it be that you mixed up bitwise and operator & and remainder operator %?
– Michael Butscher
Nov 22 '18 at 23:34












@MichaelButscher that explains it. The code works after replacing & with %.
– Kartik
Nov 22 '18 at 23:39




@MichaelButscher that explains it. The code works after replacing & with %.
– Kartik
Nov 22 '18 at 23:39












sorry, there is a type in a & 100 != 0 the & should be %
– M4rss
Nov 23 '18 at 0:41




sorry, there is a type in a & 100 != 0 the & should be %
– M4rss
Nov 23 '18 at 0:41












1 Answer
1






active

oldest

votes


















1














a & 100 != 0 


Performs bitwise and , then compares the result to 0. It will be false even in the first iteration, since 10 & 100 = 0






share|improve this answer

















  • 2




    a & 100 != 0 is not (a & 100) != 0 as you seem to suggest, instead it's a & (100 != 0) which renders a compilation error. anyhow it seems like a typo and the OP meant a % 100 != 0.
    – Aomine
    Nov 22 '18 at 23:57










  • sorry did not noticed the typo the & in a & 100 != 0 should be %
    – M4rss
    Nov 23 '18 at 0:44




















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














a & 100 != 0 


Performs bitwise and , then compares the result to 0. It will be false even in the first iteration, since 10 & 100 = 0






share|improve this answer

















  • 2




    a & 100 != 0 is not (a & 100) != 0 as you seem to suggest, instead it's a & (100 != 0) which renders a compilation error. anyhow it seems like a typo and the OP meant a % 100 != 0.
    – Aomine
    Nov 22 '18 at 23:57










  • sorry did not noticed the typo the & in a & 100 != 0 should be %
    – M4rss
    Nov 23 '18 at 0:44


















1














a & 100 != 0 


Performs bitwise and , then compares the result to 0. It will be false even in the first iteration, since 10 & 100 = 0






share|improve this answer

















  • 2




    a & 100 != 0 is not (a & 100) != 0 as you seem to suggest, instead it's a & (100 != 0) which renders a compilation error. anyhow it seems like a typo and the OP meant a % 100 != 0.
    – Aomine
    Nov 22 '18 at 23:57










  • sorry did not noticed the typo the & in a & 100 != 0 should be %
    – M4rss
    Nov 23 '18 at 0:44
















1












1








1






a & 100 != 0 


Performs bitwise and , then compares the result to 0. It will be false even in the first iteration, since 10 & 100 = 0






share|improve this answer












a & 100 != 0 


Performs bitwise and , then compares the result to 0. It will be false even in the first iteration, since 10 & 100 = 0







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 23:38









Nenad

1408




1408








  • 2




    a & 100 != 0 is not (a & 100) != 0 as you seem to suggest, instead it's a & (100 != 0) which renders a compilation error. anyhow it seems like a typo and the OP meant a % 100 != 0.
    – Aomine
    Nov 22 '18 at 23:57










  • sorry did not noticed the typo the & in a & 100 != 0 should be %
    – M4rss
    Nov 23 '18 at 0:44
















  • 2




    a & 100 != 0 is not (a & 100) != 0 as you seem to suggest, instead it's a & (100 != 0) which renders a compilation error. anyhow it seems like a typo and the OP meant a % 100 != 0.
    – Aomine
    Nov 22 '18 at 23:57










  • sorry did not noticed the typo the & in a & 100 != 0 should be %
    – M4rss
    Nov 23 '18 at 0:44










2




2




a & 100 != 0 is not (a & 100) != 0 as you seem to suggest, instead it's a & (100 != 0) which renders a compilation error. anyhow it seems like a typo and the OP meant a % 100 != 0.
– Aomine
Nov 22 '18 at 23:57




a & 100 != 0 is not (a & 100) != 0 as you seem to suggest, instead it's a & (100 != 0) which renders a compilation error. anyhow it seems like a typo and the OP meant a % 100 != 0.
– Aomine
Nov 22 '18 at 23:57












sorry did not noticed the typo the & in a & 100 != 0 should be %
– M4rss
Nov 23 '18 at 0:44






sorry did not noticed the typo the & in a & 100 != 0 should be %
– M4rss
Nov 23 '18 at 0:44





Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...