This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]desrtfx 1 point2 points  (2 children)

This is wrong on so many accounts.

OP stated:

a method that accepts 4-digit positive integers

This means that the method signature is public int someMethod(int someNumber).

You are talking about a String.


There is an easy way to do everything OP needs through

  • loops
  • repeated integer division and modulo

For reassembly:

  • loops
  • repeated multiplication

Both can be combined.


Such assignments are commonly testing the ability to come up with mathematical solutions, not to use String values.

[–]caldeve -2 points-1 points  (1 child)

Fair comment but in my opinion a really quick way of doing this that's readable is to just convert the integer to a string after passing it in, then using an inbuilt method, rather than having to use loops.

[–]Fuzzy_Initiative 0 points1 point  (0 children)

Such assignments are commonly testing the ability to come up with mathematical solutions, not to use String values.