Java Novice Help

I’m new to Java, and I’m facing an issue that I can’t resolve. I was wondering if I could have some help.
I was asked to do a program about data handling of various events of triathlon.
Inputs:

  • Number of events
  • Times in which the athlete completed the different phases
    Outputs:
  • Slowest time of all events he participated
  • Avarage time for each phase

The issue here is that I can’t do the data handling for all of the events. It only does for the last input of the cycle for that I’ve created.

Here is some of the code I wrote (I’m just showing the example for 1 phase):

System.out.println("Number of events: ");
n_events = read.nextInt();

for (k = 0; k < n_events; k++) {

        System.out.println("Name of the event:");
        name_event = read.next();
        
        System.out.println("Time swimming");
        hours_swim = read.nextInt();                      
        min_swim = read.nextInt();
        sec_swim = read.nextInt();
        time_swim = hours_swim*3600 + min_swim*60 + sec_swim;
        total_swim = total_swim + time_swim;

        if (time_swim > slowest_swim) 
              slowest_swim = time_swim;
        else if   //for the other phases

System.out.println("Slowest time of all events for swimming is: " + slowest_swim);

Hm, this looks like Java, not Javascript.

What exactly do you mean by that? Are some input values ignored? Maybe an example would be best.

Yes it’s Java, my mistake. Sorry.

In the meantime, I was able to resolve the issue. I was just calling out the wrong variables.
Thank you for your help tho.

1 Like