-1
import java.util.*;

public class NumberSplit {
static Scanner console = new Scanner(System.in);

    public static void main(String[] args) {

       int rem1, rem2, rem3, rem4;        

        System.out.print("Enter a positive integer: ");
        int num = console.nextInt();

        rem1 = num / 1000;
        num = num % 1000;

        rem2 = num / 100;
        num = num % 100;

        rem3 = num / 10;
        num = num % 10;
        rem4 = num % 10;

        System.out.println("The digits in your number are: " + rem1 + ", " + rem2 + ", " +  rem3 + ", " + rem4 + ".");
   }
}
GBlodgett
  • 12,704
  • 4
  • 31
  • 45
Aulendil
  • 9
  • 4
  • Use an array to store the digits, loop while `num` is more than zero, store `num % 10` in the array and divide `num` by ten – GBlodgett Dec 05 '18 at 19:08
  • i have done so. my only problem is storing the remainders as individual variables so that i can print them in the final print out statement – Aulendil Dec 05 '18 at 19:21
  • Like I said use an `Array` to store the remainders. – GBlodgett Dec 05 '18 at 19:23

1 Answers1

0

You can use Stream API:

String result = Arrays.stream(String.valueOf(num).split(""))
                    .collect(joining(", ", "The digits in your number are: ", "."))
Ousmane D.
  • 54,915
  • 8
  • 91
  • 126