0

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);

}
}
2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by adarshcu
0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.