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 the last two digits of a given integer in java.
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("Last two digit is: "+num);
}
}
Output:
Enter a number:4567
Last two digit is: 67