Results 1 to 3 of 3

Thread: java

  1. #1
    Join Date
    Feb 2014
    Posts
    1
    Rep Power
    0

    Default java

    I dnt know how to solve this problem
    Given a string which contains a number as input, the objective is to create an array arr, such that arr[i] represents the number of times the digit i appeared in the string. Note that the maximum value of i in arr[i] will be 9 as the digits are 0,1,2,3,4,5,6,7,8,9.
    getDigitArray("9988776655")={0,0,0,0,0,2,2,2,2,2}
    getDigitArray("123456789013579")={1,2,1,2,1,2,1,2, 1,2}

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: java

    Do you know how to allocate arrays?

    Do you know how to write a for loop?

    Do you know how to get a character from a certain position in a string?
    Get in the habit of using standard Java naming conventions!

  3. #3
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    184
    Rep Power
    0

    Default Re: java

    Here is what you need to know:

    EITHER string.charAt(index) OR string.substring(start index, end index)

    Initializing/declaring arrays....
    Java Code:
    int[] arr = new int[size];
    Where size = the numbers of elements in the array, which would be 10 for you (0,1,2,3,4,5,6,7,8,9)

    You could also use string.indexOf and keep checking until you get -1


    Read up on those

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
  •