Question
IN JAVA Write a method called updateTally, which calls nthDigit. updateTally takes in three arguments, an int n, an int num, and an int[] tally.
IN JAVA Write a method called updateTally, which calls nthDigit. updateTally takes in three arguments, an int n, an int num, and an int[] tally. We assume that tally is a int[] of 10 integers. The tally contains the tally of the number of n th digits seen so far. It updates tally to reflect the n th digit of num. In other words, if 5 is the n th digit of num, we increment index 5 of tally. If 2 is the n th digit of num, we increment index 2 of tally. If d is the n th digit of num, we increment index d of tally. Examples showing how tally changes:
updateTally(2, 1072, [0,0,1,2,0,0,3,0,9,0]) [0,0,1,2,0,0,3,1,9,0]
updateTally(0, 2541, [0,0,1,2,0,0,3,0,9,0]) [0,0,2,2,0,0,3,0,9,0]
Remember, since we are modifying tally, updateTally will be a void method which returns nothing.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started