• 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

OCA/OCP K&B Book question

 
Greenhorn
Posts: 7
1
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I Really dont know why the mask gets 2 increment if there is only one mask++ in the code and I more that sure when you refer a variable to itself it does not increment, so I am really confused I really dont know what it is.

Look at the following atachement.
ranch.png
[Thumbnail for ranch.png]
Question
 
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alejandro Daza wrote:I Really dont know why the mask gets 2 increment if there is only one mask++ in the code and I more that sure when you refer a variable to itself it does not increment, so I am really confused I really dont know what it is.

Look at the following atachement.



public class Spock{
  public static void main(String[] args){

  int mask = 0;
  int count = 0;
  if(((5<7) || (++count < 10)) | mask++ < 10) mask =mask; // mask gets incremented after testing condition so mask = 1
  if((6 > 8) ^ false) mask =mask; // condition is always false as false XOR false is TRUE; skips to the next condition
  if(!(mask > 1)&& ++count > 1) mask =mask; // Evaluates to false as count is incremented before testing condition so skips to next line
  System.out.println(mask + " " + count); // mask = 1 and count count = 1

  }

I hope that helps

}
 
Jean Claude Uwimpuhwe
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I hope that helps
 
Alejandro Daza
Greenhorn
Posts: 7
1
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, So I am right, the answer on the book is incorrect then.
 
Ranch Hand
Posts: 499
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alejandro Daza wrote:I Really dont know why the mask gets 2 increment if there is only one mask++ in the code and I more that sure when you refer a variable to itself it does not increment, so I am really confused I really dont know what it is.



Alejandro Daza wrote:Thanks, So I am right, the answer on the book is incorrect then.


Assuming we have the same book, it's possible that some of the originally posted question was truncated.  If so, the book answer would be correct.

   
Untitled.png
[Thumbnail for Untitled.png]
 
reply
    Bookmark Topic Watch Topic
  • New Topic