Java program to print the two digits of the year

Java program to print the two digits of the year. A Java program to extract the year’s last two digits. As an input, you can use any integer. The last two digits of the provided integer are then extracted as output using modulus and division operations. The source code for the Java Program to Extract the Last Two Digits of a Year can be found here.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int x, y, i = 0;
String z = "";
Scanner s = new Scanner(System.in);
System.out.print("Enter the year");
x = s.nextInt();
while(i < 2)
{
y = x % 10;
z = y + "" +z;
x = x / 10;
i++;
}
System.out.println("Last two digits"+z);
}
}

 

Output:

Enter the year 1980
Last two digits 80

pre increment vs post increment in java programming

After utilizing a variable in an expression, the post increment operator is used to increase its value. The value is used inside the expression and then incremented by one in the post increment. Both increase the value, but I does so before the current expression is evaluated, whereas i++ does so after the expression has been evaluated.