Results 1 to 4 of 4
  1. #1
    nicholil is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default 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");

    }

    }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Please don't double post; I answered your identical question in your other thread.

    kind regards,

    Jos

  3. #3
    nicholil is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default 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

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Exception in thread "main" java.lang.Error ...
    By mossy in forum New To Java
    Replies: 7
    Last Post: 10-31-2010, 09:53 AM
  2. Replies: 5
    Last Post: 06-22-2010, 03:51 PM
  3. Replies: 1
    Last Post: 11-20-2009, 07:58 PM
  4. Replies: 1
    Last Post: 08-07-2007, 07:10 AM
  5. Replies: 1
    Last Post: 07-25-2007, 10:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •