-1

So my question is how can I retrieve the penultimate digit of the number that the user wrote down? Below is my code so far:

Console.Write("Write a numeral: ");
string s = Console.ReadLine();
int a = int.Parse(s);
nikovn
  • 1,900
  • 5
  • 22
  • 28

1 Answers1

1

If you mean penultimate digit in the number then

var penultimate = (a / 10) % 10;

should give you the value.

However, it's also highly advisable to check if the number has at least 2 digits

a => 10 || a <= -10

And also handle the possibility that the input is not a number.

nikovn
  • 1,900
  • 5
  • 22
  • 28