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 DesignProgram or Solutionimport 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 Explanation1. Get two inputs num1 and num2 2. extract the last digits of num1 and num2 using %10, 3. then compare last digits.
Get the answer to your homework problem. Try Numerade free for 7 days
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. Ruby Code Editor: Contribute your code and comments through Disqus. Previous: Write a Ruby program to print the elements of a given array.
What is the difficulty level of this exercise?
Warmup-1 > lastDigit
Page 2Warmup-1 Simple warmup problems to get started (solutions available). New videos: String Introduction, String Substring, If Boolean Logic 1, If Boolean Logic 2 Java HelpMisc 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
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 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. |