Java Chapters

Java Program for the right most digit of a number.

Structure of JAVA Programs - Overview
import java.util.Scanner;

public class Program 
{
    public static void main( String[] args ) 
    {
        int Num, Right_Num;
        Scanner reader = new Scanner(System.in);
        
        System.out.print("Enter Number : ");
        Num = reader.nextInt();
        
        Right_Num = Num % 10;
        
        System.out.print("\n\nThe right most digit is : " + Right_Num);
    }
}

Output :
Enter Number : 123

The right most digit is : 3

Description :

Modulo (%) operator gives reminder of division of two numbers.
So Reminder of 123/10 is 3 the right most digit.


Leave a comment
Recent Comments
No Comments