by CodeChum Admin
Manipulating values from a series of numbers is fun, but let's try exploring the use of loops a little more.
How about printing out each digit of a number starting from its rightmost digit, going to its leftmost digit?
Instructions:
Input
A line containing an integer.
214
Output
Multiple lines containing an integer.
4
1
2
import java.util.Scanner;
public class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int number = in.nextInt();
while (number > 0) {
int digit = number % 10;
number = number / 10;
System.out.println(digit);
}
in.close();
}
}
Comments
Leave a comment