This is a Java Program to Extract Last two Digits of a given Year.
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.
import java.util.Scanner;
public class Extract_Digit
{
public static void main(String[] args)
{
int x, y, i = 0;
String z = "";
Scanner s = new Scanner(System.in);
System.out.print("Enter 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:
$ javac Extract_Digit .java $ java Extract_Digit Enter Year:2014 Last two digits:14
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
Here’s the list of Best Reference Books in Java Programming, Data Structures and Algorithms.