Java Program to find the whether the last digit of given two numbers are equal or not

Description

Get two numbers num1 and num2 and check whether last digit of num1 and num2  are equal or not?.
Input:
65 45
Ouput:
Last Digits are Equal.

Input:
35 38
Output:
Last Digits are Not Equal

Solution

import java.util.*;
class LastDEqual
{
  public static void main(String args[])
  {
     int num1,num2;
     Scanner sc=new Scanner(System.in);
     System.out.println("Enter two numbers:");
     num1=sc.nextInt();
     num2=sc.nextInt();
	if(num1%10==num2%10)
	{
		System.out.println("Last Digits Are Equal.");
	}
	else
	{
		System.out.println("Last Digits Are Not Equal.");
	}
  }
}

Explanation

extract the last digits of num1 and num2 using %10, then compare last digits.
Ramesh P Natarajan

Author - Ramesh P Natarajan

Learner, Professor, Technology Trainer, Software Developer and Content Marketer, very much passionate in the field of Software Application Development, Machine Learning and Search Engine Optimization.

Write to: admin@decodeschool.com





Interesting Pattern Programs: for more Patterns

Input:
5
Output:
*
**
***
****
*****
****
***
**
*Solution
Input:
5
Output:
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *Solution
Input:
5
Output:
*        *
**      **
***    ***
****  ****
**********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********
**** ****
***   ***
**     **
*       *Solution
Input:
5
Output:
*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********Solution