Results 1 to 3 of 3

Thread: java

  1. #1
    Join Date
    Feb 2014
    Rep Power

    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("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
    Tucson, AZ
    Rep Power

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

    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