Java Program to print last two digits of a given integer


In this program, You will learn how to print the last two digits of a given integer in Java.


23 = 123 % 100

34 = 1234 % 100


Example: How to print last two digits of a given integer in Java

Run it Now
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        int n;

        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a number :");
        n = sc.nextInt();

        int num = n % 100;

        System.out.println("\nLast two digit is: "+num);

    }
}

Output:

Enter a number :123
Last two digit is: 23