Results 1 to 4 of 4
- 11-06-2010, 09:18 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
I am having a compile tile error. please help.Exception in thread "main" java.lang.Ar
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package londondm2;
import java.util.*;
import java.io.*;
/**
*
* @author NicholiL
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String[] names = {"Elena", "Demetris", "Katarina", "Phil", "Matteo", "Alexis", "Emmauel", "Amir", "Daniel", "Neda"};
int[] timesMin = {341, 273, 334, 445, 402, 388, 273, 334, 399, 343};
int[] timesSec = {25, 30, 37, 44, 56, 5, 12, 51, 14, 27};
System.out.println("\n");
System.out.print("Program print the runner and print his/her name and time achieved");
System.out.println("\n");
System.out.println("\n");
System.out.println("Please enter the time and mins of person to find: ");
String mins_str = args[0];
int minutes = Integer.parseInt(mins_str);
String sec_str = args[0];
int secs = Integer.parseInt(sec_str);
int IndexOfMins;
int IndexOfsecs = 0;
int IndexOfPerson;
boolean isValidMins = false;
boolean isValidSecs = false;
//search the mins array to check if the input mins is included
//If includede find the position
//Array startts for 0,1,2,....
for (int i = 0; i < timesMin.length; i++) {
if (minutes == timesMin[i]) {
IndexOfMins = i;
isValidMins = true;
break;
}
isValidMins = false;
}
//check if the mins is found in the mins array
//i.e isvalid = true
//if so then search the secs
if (isValidMins) {
for (int i = 0; i < timesSec.length; i++) {
if (secs == timesSec[i]) {
IndexOfsecs = i;
isValidSecs = true;
break;
}
isValidSecs = false;
}
System.out.println("The name could not be found for the mins and secs you provided\n");
}
//check if the secs is found in the secs array
//if so then we proceed to find the name
if (isValidSecs) {
//Next
//We find the name in the array
//First we need to check to make sure the IndexOfsec and IndexOfMins
//should be the same . Meaning they are on the same position in the table
//so we can then reference the name attribute to them
System.out.print("The name is: " + names[IndexOfsecs]);
} else {
System.out.println("The name could not be found for the mins and secs you provided\n");
}
}
}
- 11-06-2010, 10:38 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,605
- Blog Entries
- 7
- Rep Power
- 17
Please don't double post; I answered your identical question in your other thread.
kind regards,
Jos
- 11-06-2010, 11:01 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
double posting
Sorry about that. I wanted to edit it to add the runtime error but not sure how to do that. Will do it differently from now on. Thanks
- 11-06-2010, 12:33 PM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
Exception in thread "main" java.lang.Error ...
By mossy in forum New To JavaReplies: 7Last Post: 10-31-2010, 09:53 AM -
Question about error "Exception in thread "main" java.lang.NoSuchMethodError: main
By ferdzz in forum New To JavaReplies: 5Last Post: 06-22-2010, 03:51 PM -
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 07:58 PM -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM -
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
By romina in forum New To JavaReplies: 1Last Post: 07-25-2007, 10:55 PM


LinkBack URL
About LinkBacks

Bookmarks