Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# look for the best arithmetic

Greenhorn
Posts: 24
There are 5 events, they (24 hours) occurs in one day , the number of occurrences stored in the array timeCount [i] [j], where i = 0,1,2,3,4 ,says that five events; j = 0 , 1,2 ,...... 22,23, respectively 0:00 to 1:00, 1:00 to 2:00 ...... 23:00 to 0:00,says that the number of occurrences of each hour, output the bet time period which are the highest number of the 5 events , I think the key is to find out that some of the best time period to make the event most often occurs during this time period.

How to make it using java?

Bartender
Posts: 563
I think the problem is asking the program to sum the number of events for each hour and return the hour with the largest sum of the 5 events. So in pseudo code, the program would look something like

The problem statement suggests that one hour will be a clear winner, but the above doesn't account for the possibility of there being more than one hour with the same number of max events.

Song Guo
Greenhorn
Posts: 24
For instance(event 1),0:00-1:00,the occurrence is 2,1:00-2:00 100,2:00-3:00 120.Output is 1:00-3:00,the occurrence is 220 istead of 0:00-3:00,the occurrence is 221(1 is very small compared to 100).How to find the time period like this ? Thanks!

Greg Brannon
Bartender
Posts: 563
If you want to find the maximum occurrence of a single event rather than the sum of the five events, you'll have to search each element of the array for the max value. When you find the max value, the i, j indexes of that value will provide your answer: the max event will be i + 1 and the hour that the max event occurred will be j to j + 1 (or j to 00, if j = 23).

I won't code it for you. Attempt to code it yourself. If you get stuck, come back with your code to show what you need help with.

 It is sorta covered in the JavaRanch Style Guide.