Java method on return position of integer

Write the method position() which returns the position of the first appearance of a specified digit in a
positive number n. The position of the digit is counted from the right and starts from 1. If the required
digit is not in the number, the method should return -1. For example, position(12315, 1) returns 2 and
position(12, 3) returns -1. No error checking on the parameters is required in the method. The method
header is given below:
public static int position(int n, int digit)
Test cases: (1) n : 12345, digit : 3; (2) n : 123, digit : 4; (3) n : 12145, digit : 1;
Expected outputs: (1) position = 3; (2) position = -1; (3) position = 3.
5465da
Asked Jan 28, 2017

TIP: If it's not your answer to this question, please click "Leave a Comment" button under the question to communicate with the question owner.

Categories