Given two non negative values print true if they have the same last digit, such as with 27 and 57

Get two numbers num1 and num2 and check whether last digit of num1 and num2 are equal or not?.

Sample Input 1:

65 45

Sample Output 1:

Last Digits are Equal.

Sample Input 2:

35 38

Sample Output 2:

Last Digits are Not Equal

Flow Chart Design

Program or 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."); } } }

Program Explanation

1. Get two inputs num1 and num2

2. extract the last digits of num1 and num2 using %10,

3. then compare last digits.

Given two non negative values print true if they have the same last digit, such as with 27 and 57

Given two non negative values print true if they have the same last digit, such as with 27 and 57
Given two non negative values print true if they have the same last digit, such as with 27 and 57

Get the answer to your homework problem.

Try Numerade free for 7 days

We don’t have your requested question, but here is a suggested video that might help.

Find the integer such that a = 17(mod 29) and -14 < a < 14. a = 31(mod 10) and 80 < a < 90. a = 24(mod 17) and -34 < a < -17.

Given two non negative values print true if they have the same last digit, such as with 27 and 57

Ruby Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Ruby program to print the elements of a given array.
Next: Write a Ruby program to retrieve the total marks where subject name and marks of a student stored in a hash.

What is the difficulty level of this exercise?



Share this Tutorial / Exercise on : Facebook and Twitter

  • Exercises: Weekly Top 16 Most Popular Topics
  • SQL Exercises, Practice, Solution - JOINS
  • SQL Exercises, Practice, Solution - SUBQUERIES
  • JavaScript basic - Exercises, Practice, Solution
  • Java Array: Exercises, Practice, Solution
  • C Programming Exercises, Practice, Solution : Conditional Statement
  • HR Database - SORT FILTER: Exercises, Practice, Solution
  • C Programming Exercises, Practice, Solution : String
  • Python Data Types: Dictionary - Exercises, Practice, Solution
  • Python Programming Puzzles - Exercises, Practice, Solution
  • C++ Array: Exercises, Practice, Solution
  • JavaScript conditional statements and loops - Exercises, Practice, Solution
  • C# Sharp Basic Algorithm: Exercises, Practice, Solution
  • Python Lambda - Exercises, Practice, Solution
  • Python Pandas DataFrame: Exercises, Practice, Solution
  • Conversion Tools
  • JavaScript: HTML Form Validation

Warmup-1 > lastDigit
prev  |  next  |  chance

Given two non-negative int values, return true if they have the same last digit, such as with 27 and 57. Note that the % "mod" operator computes remainders, so 17 % 10 is 7.

lastDigit(7, 17) → truelastDigit(6, 17) → false

lastDigit(3, 113) → true

...Save, Compile, Run (ctrl-enter)


Page 2

Warmup-1

Given two non negative values print true if they have the same last digit, such as with 27 and 57
Given two non negative values print true if they have the same last digit, such as with 27 and 57
Given two non negative values print true if they have the same last digit, such as with 27 and 57
Given two non negative values print true if they have the same last digit, such as with 27 and 57
Given two non negative values print true if they have the same last digit, such as with 27 and 57
Given two non negative values print true if they have the same last digit, such as with 27 and 57
Given two non negative values print true if they have the same last digit, such as with 27 and 57
Given two non negative values print true if they have the same last digit, such as with 27 and 57
chance

Simple warmup problems to get started (solutions available). New videos: String Introduction, String Substring, If Boolean Logic 1, If Boolean Logic 2

Java Help

Misc Code Practice

Given two non-negative int values, return true if they have the same last digit, such as with 27 and 57. Note that the % "mod" operator computes remainders, so 17 % 10 is 7.

lastDigit(7, 17) → true lastDigit(6, 17) → false lastDigit(3, 113) → true

Given two non negative values print true if they have the same last digit, such as with 27 and 57


public boolean lastDigit(int a, int b) { String strA = Integer.toString(a); String strB = Integer.toString(b); if (strA.charAt(strA.length() - 1) == strB.charAt(strB.length() - 1)) return true; else return false; }

Instantly share code, notes, and snippets.

Given two non-negative int values, return true if they have the same last digit, such as with 27 and 57. Note that the % "mod" operator computes remainders, so 17 % 10 is 7.

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.