Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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

if-then-else example / OCA Java SE 8 Study Guide

 
Greenhorn
Posts: 16
2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Starting on page 67, the text gives several examples of the 'if' statement, using a variable hourOfDay, "an integer value from 0 to 23."

While not necessarily an error, I wonder why afternoon begins at 11:00?

[note: I have added the comments]



Why not this instead, where afternoon begins with 12?

 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Disclaimer: I haven't read OCA Java SE 8 Study Guide Edit subject


What is the the lowest value of hourOfDay? Zero or one?
Based on

prints between 11 and 23, inclusive

which would indicate zero. So noon will be 11.

In case it is so, and you are thinking why, it is probably because of the norm that the 1st element in an array or list has the index 0 and not 1
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adding in minutes, 0 would cover 00:01 to 00:59, and 11 would cover 11:00 to 11:59, so no, unless there's something else about the hours in the book in question, a 24 hour clock does not have afternoon beginning at 11.
It begins at 12:00.

Nothing to do with arrays.
 
Dwight Webber
Greenhorn
Posts: 16
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hourOfDay is "an integer value from 0 to 23," so 0 is midnight and 12 is noon.

As I said, I wonder why afternoon begins at 11.

Maybe the authors will comment.
 
author & internet detective
Posts: 41851
904
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
Shrug. We were focused on the if statement? No good reason.
 
reply
    Bookmark Topic Watch Topic
  • New Topic