Results 1 to 4 of 4

Thread: String to int

  1. #1
    willemuk is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default String to int

    Can anyone tell me what is wrong with this method?? It keeps asking for an array.

    public int totalSeconds() {
    String duration = "15:20";

    String[] durationParts = duration.split(":");

    int totalSeconds = (Integer.parse(duration[0]) * 60) + Integer.parse(duration[1]);
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,019
    Blog Entries
    7
    Rep Power
    20

    Default Re: String to int

    Your array is named 'durationParts', not 'duration'.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    mjsudesh is offline Member
    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    Default Re: String to int

    Hi, try this.........
    int totalSeconds = (Integer.parseInt(durationParts[0]))*60 +Integer.parseInt(durationParts[1]);
    it will work

  4. #4
    willemuk is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Re: String to int

    A great big thank you to both of you for answering my question. I really appreciate it. Thanks

Similar Threads

  1. Replies: 3
    Last Post: 02-10-2012, 06:26 PM
  2. Replies: 1
    Last Post: 12-15-2011, 12:39 PM
  3. Replies: 12
    Last Post: 11-26-2010, 08:33 AM
  4. Replies: 1
    Last Post: 11-04-2010, 06:53 PM
  5. Replies: 0
    Last Post: 11-20-2007, 04:59 PM

Tags for this Thread

Posting Permissions

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