-3

I'm creating a very basic encryption program, and I'm stuck. Essentially the user inputs a 4 digit int using a scanner and my goal is to, encrypt each digit, using a set formula. But i can't figure out how to, extract each digit and insert it into the formula. if anyone knows the simplest way of doing so, id really appreciate it.

Zito.
  • 15
  • 3
  • 5
    http://stackoverflow.com/questions/3389264/how-to-get-the-separate-digits-of-an-int-number – Aschab Oct 07 '16 at 14:43

2 Answers2

1

You can get each digit using a modulus operation.

In this case use base ten. 56 % 10 = 6. Then divide by 10 remove the last digit. 56/10 = 5 (because of integer division). Repeat for each digit.

Brion
  • 746
  • 3
  • 10
0

String.split("") will split a String into all its parts:

String input = "1234";
System.out.println(Arrays.toString(input.split("")));
// output: [1, 2, 3, 4]