Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

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

 
Greenhorn
Posts: 16
2
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • 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
 
Master Rancher
Posts: 4710
49
  • Mark post as helpful
  • send pies
  • 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
  • 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: 40245
819
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shrug. We were focused on the if statement? No good reason.
 
This tiny ad is suggesting that maybe she should go play in traffic.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic