954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Marathon

// 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[i] + ": " + times[i]);
times[i]=i;
double minutes = 60.0;
double x = (times[i]/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?

lgbagabuyo
Light Poster
25 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

times[i]=i;

JamesCherrill
Posting Genius
Moderator
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

P.S. I forgot to mention:

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

lgbagabuyo
Light Poster
25 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

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

JamesCherrill
Posting Genius
Moderator
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

I thought Im done with this but, not

lgbagabuyo
Light Poster
25 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

I'm sorry to hear that.

JamesCherrill
Posting Genius
Moderator
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

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 <<<<<

lgbagabuyo
Light Poster
25 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

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

lgbagabuyo
Light Poster
25 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: