// Loel Jolito Niño C. Bagabuyo
package marathon;


public class Marathon {



public static void main(String[] args) {
String[] names = {
"Jessabel", "Jerome", "Kristine", "Rodel", "Grajen", "Reymart", "Kevin",
"Sherwin", "Orniel", "John", "Kirk", "Jovert", "Rhea", "Mariella","Melart", "Michael"
};


double[] times = {
341.0, 273.0, 278.0, 329.0, 445.0, 402.0, 388.0, 275.0, 243.0, 334.0, 412.0, 393.0, 299.0, 343.0, 317.0, 265.0
};



for (int i = 0; i < times.length; i++) {
System.out.println(names + ": " + times);
times=i;
double minutes = 60.0;
double x = (times/minutes);
System.out.println(x);


}


}
}

This is my code iam using netbeans but I couldn't get the right minute for:
example 341/60 = 0.0 (wrong answer)<<< this is my output
341/60 = 5.6833 (Right answer)
Where did I go wrong?

Recommended Answers

All 7 Replies

times=i;

P.S. I forgot to mention:

How do I print the 1st fastest runner and the 2nd fastest runner?

loop through the times array to find the lowest time, then do it again for the lowest excluding that one.

I thought Im done with this but, not

I'm sorry to hear that.

public class Marathon {
int x = 0;

public static void main(String[] args) {

String[] names = new String[]{"Jessabel", "Jerome", "Kristine", "Rodel", "Grajen", "Reymart", "Kevin",
"Sherwin", "Orniel", "John", "Kirk", "Jovert", "Rhea", "Mariella","Melart", "Michael"};


double[] times = new double[]{341.0, 273.0, 278.0, 329.0, 445.0, 402.0, 388.0, 275.0, 243.0, 334.0, 412.0, 
    393.0, 299.0, 343.0, 317.0, 265.0};

int t = 0;
for (int i = 0; i < times.length; i++){                
System.out.println(names[i] + ": " + times[i]);
}
for(int i = 0;i< times.length; i++)
{ 
for (int j = i + 1; j < times.length; j++)
    if (times[i] > times[j])
    {
        t = (int)times[i];
        times[i] = times[j];
        times[j] = t;
    }
}
System.out.println("The Winners for 1st and 2nd fastest runner");

for (int i = 0; i < 2; i++){
    for (int x = 0; x < 1; x++){

System.out.println(names[8] + "\t");

System.out.println(names[15] + "\t");
System.out.println(": " + times[i]);


}}}}

What did I do wrong?
The part highlighted with red at the bottom is my problem, I can't print it with its corresponding time please help
this is my output:

Jessabel: 341.0
Jerome: 273.0
Kristine: 278.0
Rodel: 329.0
Grajen: 445.0
Reymart: 402.0
Kevin: 388.0
Sherwin: 275.0
Orniel: 243.0
John: 334.0
Kirk: 412.0
Jovert: 393.0
Rhea: 299.0
Mariella: 343.0
Melart: 317.0
Michael: 265.0
The Winners for 1st and 2nd fastest runner
Orniel  
Michael 
: 243.0
Orniel  
Michael 
: 265.0

This is my second code, this is located above highlighted with red(codes)

System.out.println("The Winners for 1st and 2nd fastest runner");

for (int i = 0; i < 2; i++){
    for (int x = 0; x < 1; x++){
System.out.println(names[8] +": " + times[i]);
System.out.println(names[15] +": " + times[i]);

Its Output:

The Winners for 1st and 2nd fastest runner
Orniel: 243.0 <<< this is one is fine
Michael: 243.0 <<<<<<This is my problem, I want this to be not here but how?
Orniel: 265.0 <<<<<<<This is my problem, I want this to be not here but how?
Michael: 265.0 <<< this is also fine
public class Marathon {
public static void main(String[] args) {
String[] names = new String[]{"Jessabel", "Jerome", "Kristine", "Rodel", "Grajen", "Reymart", "Kevin",
"Sherwin", "Orniel", "John", "Kirk", "Jovert", "Rhea", "Mariella","Melart", "Michael"};


double[] times = new double[]{341.0, 273.0, 278.0, 329.0, 445.0, 402.0, 388.0, 275.0, 243.0, 334.0, 412.0, 
    393.0, 299.0, 343.0, 317.0, 265.0};


int t = 0;
for (int i = 0; i < times.length; i++){                
System.out.println(names[i] + ": " + times[i]);
}
for(int i = 0;i< times.length; i++){ 
for (int j = i + 1; j < times.length; j++)
    if (times[i] > times[j])
    {
        t = (int)times[i];
        times[i] = times[j];
        times[j] = t;
    }
}
System.out.println("The Winners for the fastest runner are");
for (int i = 0; i < 1; i++){
System.out.println("The First fastest runner "+ names[8]+ " : "+ times[i]);
}
for(int i = 1; i < 2; i++){
System.out.println("The second fastest runner "+ names[15]+ " : "+  times[i]);
}}}

Its Done here's the code

Thanks for viewing

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.