Got this problem I have been struggling on for hours that is extra credit for my class:
Write a recursive method that returns the currency format of the given integer value (val ). All inter-mediate operations must be carried out as integer arithmetic. The only time you are allowed to use string operations is to return the result. You may use the String.valueOf() or Long.toString() methods. Recall that 27341 % 1000 is 341 and 27341 / 1000 is 24.
public String formatAsCurrency(long val) { }
For this question, make sure your method works correctly for numbers that are multiple of 1000 or has consecutive zeros. Examples:
Got this problem I have been struggling on for hours that is extra credit for my class:
Write a recursive method that returns the currency format of the given integer value (val ). All inter-mediate operations must be carried out as integer arithmetic. The only time you are allowed to use string operations is to return the result. You may use the String.valueOf() or Long.toString() methods. Recall that 27341 % 1000 is 341 and 27341 / 1000 is 24.
public String formatAsCurrency(long val) { }
For this question, make sure your method works correctly for numbers that are multiple of 1000 or has consecutive zeros. Examples:
if val < 1000 you need to return val as string else you need to contatenate the result of applying formatAsCurrency, which have as argument (val - (val % 1000))/1000, with a comma and the rest val % 1000.
Thanks, it got me started but still stuck, hopefully i can get some credit. Its an upcoming topic in my class and is extra credit on homework since we haven't really learned it yet.
Thanks, it got me started but still stuck, hopefully i can get some credit. Its an upcoming topic in my class and is extra credit on homework since we haven't really learned it yet.
ok, you say you are stuck, what is the problem? i hope not writing in java because my knowledge of java are very poor,
I know some what how Recursive writing works for Java. I know that first is the base case, but then i get confused to how to set up the recursive call(s) after that.
I know some what how Recursive writing works for Java. I know that first is the base case, but then i get confused to how to set up the recursive call(s) after that.
when you call formatAsCurrency(5000481L) and you implement what i said, first step will be to check if val is less then 1000L.
obvious in this case the test will fail then you will return the result of concatenation between the result of calling formatAsCurrency(5000L) with a comma, ",", and the rest 481L.
formatAsCurrency(5000L) will do same thing because 5000L > 1000L but this time will call formatAsCurrency(5L) wich will return '5' a string because is less then 1000L.
so after each return and concatenation will have 5,000,481
no,
three reasons:
1. you can't learn if i write
2. is a homework, read forum rules, i can help you but not this way
3. my knowledge of java are poor, as i said.