Enter any integer as input. After that we perform modulus and division operations to extract last two digits of the given integer as output.
Here is the source code of the Java Program to Extract Last two Digits of a given Year. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Extract_Digit
public static void main(String args)
int x, y, i = 0;
String z = "";
Scanner s = new Scanner(System.in);
x = s.nextInt();
while(i < 2)
y = x % 10;
z = y + "" +z;
x = x / 10;
System.out.println("Last two digits:"+z);
$ javac Extract_Digit .java $ java Extract_Digit Enter Year:2014 Last two digits:14
Sanfoundry Global Education & Learning Series – 1000 Java Programs.