Java program to print the number positions in list of digits

Java program to print the number positions in list of digits. This is a Java program for extracting digits from an integer value. As an input, you can use any integer. After that, we perform operations such as modulus and division to determine the number of digits in a given integer, and then we print each of the digits. The Java Program to Extract Digits from a Given Integer source code is available here.

import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int n, m, a, i = 1, checker = 0;
Scanner s=new Scanner(System.in);
System.out.print("Enter any numbers");
n = s.nextInt();
m = n;
while(n > 0)
{
n = n / 10;
checker++;
}
while(m > 0)
{
a = m % 10;
System.out.println("numbers position is "+checker+":"+a);
m = m / 10;
checker--;
}
}
}

 

Output:

Enter any numbers  4567
numbers position is 4:7
numbers position is 3:6
numbers position is 2:5
numbers position is 1:4

What is pre increment and post increment in java

Before assigning value to variable, the pre increment operator is used to increase its value by 1. After assigning value to variablethe post increment operator is used to increase its value by one.

While loop and how it works in java program

The condition is assessed first in a while loop, and if it returns true, the statements inside the while loop are executed. This process is repeated until the condition returns false. When the condition returns false, the control exits the while loop and moves on to the next sentence in the program.