Write a program that prompts the user to input a four - digit positive integer.The program then outputs the digits of the number one digit per line

Taylor Hyles wrote that in 2016: Be sure to give credit to their contribution:

import java.util.*;
import java.io.Console;

public class FourDigit {

public static void main(String[] args) {
  Console console = System.console();
  LinkedList<Integer> stack = new LinkedList<Integer>();
  int digits = 0;

  do {
  String response = console.readLine("Enter a four digit integer:");
   try{
    digits = Integer.parseInt(response);
   }
    catch (NumberFormatException e){  
    }
    if (1000 > digits || digits > 9999){
      System.out.println("Please try again...");
    }
  }
  while(1000 > digits || digits > 9999);

  while (digits > 0) {
    stack.push( digits % 10 );
    digits = digits / 10;
  }

  while (!stack.isEmpty()) {
    System.out.println(stack.pop());
  }
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.