i have to create a DigitsDisplay application that prompts the user for a non negative integer and then displays each digit on a separate line like such
"Enter a positive integer: 789
7
8
9

this is what i have so far
Can someone please help me fix this program ?
im very new to java

import java.util.Scanner
public class DigitsDisplay
{
  public static void main(String[] args)
  {
int maxVal = 10000000;
int userInput;
Scanner input = new Scanner (System.in);
 
    System.out.print("Enter a positive integer: ");
    userInput= input.nextInt();
while (maxVal > userInput) {
maxVal = maxVal/10;
}
int value1 = userInput % maxVal; 
System.out.print(userInput/maxVal);

}
}

Recommended Answers

All 2 Replies

i have to create this program using loop structures and modulus division

i'm not sure why you need this loop.

while (maxVal > userInput) {
maxVal = maxVal/10;
}

What i would do for this is

1. Get input from user. 
//Inside a loop now,
2. userInput % 10 , Print remainder
3. userInput = userInput/10
//exit loop

Given so many hints , you should be able to do it. Please determine the entry and exit conditions for the loop on your own.

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.