• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OCPJP 6 Obj 2: Usage of Modulus withing for loop.

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I was attempting WhizLabs Objective 2 questions. There was this particular question about for loops, but what stumped me was the modulus operator.
I think the answer for 1%2 should be 0. However the correct answer to this question implies it should be 1. How is that so? Hope somebody can explain, thanks.

https://dl.dropboxusercontent.com/u/38167918/Computing/OCPJP/WhizLabs/Objective2/Q7.JPG

regards
John
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John,

% is the modulus or reminder operator. 1/2 = 0, 1%2=1. Because if you try to divide 1 into 2 buckets, you have a reminder of 1.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic