Largest digit in an integer!

I have the following question that I am stuck at :frowning:

Define a function that when passed an integer, returns the highest digit in the integer. Call the function in setup() by passing an integer of your choice and store the value returned in a variable result.

I don’t have any idea where and how to start. Could someone give me a hint please?

Thanks
WoH

@Who

Why don’t you start one step at a time.

  1. First, create a sketch with a setup.
  2. Next, give your function a name, and call pass it an integer. It does nothing. Run it. Working?
  3. Next, print that number in your function with println. Working?
  4. Next, return that number to setup with the return statement. Working?
  5. Ok, now you are ready to get the top digit. There are many ways to do this – including using integer division (/), or modulo(%), or converting a number to a string an manipulating the string… and more!

For feedback, please post your code and your followup question here.

Sorry misread the question so my answer was way off target.

  1. Processing.org/reference/strconvert_.html
  2. Processing.org/reference/String_charAt_.html
  3. Processing.org/reference/intconvert_.html