I am making this program that will take a positive integer and turn it into this
Ex: Enter a positive integer: 245
2
4
5

I am wondering if I am doing this right. I know there might be some parse errors. but all I am concerned with, if is the overall structure and concept of my program is correct, apreciate any help.

import java.util.Scanner
public class DigitsDisplay
{
  public static void main(String[] args)
  {
    int digit;
    Scanner input = new Scanner (System.in);

    System.out.print("Enter a positive integer: ");
    digit = input.nextInt();

    count = 0;
    
    while (digit != 0)
    {
      count + = 1;
      digit % 10;
      System.out.println(digit);
     }

The last part is definitely wrong. digit % 10, if digit = 245, will be 5. But digit never gets modified there, so your program will run forever. What you should be doing is using a combination of % and / .

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.