Problem: 2.20


Question 2.20: Write a Java program that accepts two integer values between 25 to 75 and return true if there is a common digit in both numbers.

Sample Output:

Input the first number : 35

Input the second number: 45

Result: true

Solution:



package com.company;
import java.util.Scanner;
public class Lab2problem20 {
    public static void main(String[] args)
    {
        Scanner Obj =new Scanner(System.in);
        System.out.println("enter the first value: ");
        int a =Obj.nextInt();
        System.out.println("enter the second value: ");
        int b =Obj.nextInt();
         int x = a % 10;
         int y = a/10;
         int n =b%10;
         int m = b/10;
         if(x==n || x==m || y==n || y==m)
         {
             System.out.println(true);
         }
         else{
             System.out.println(false);
         }

    }
}

Previous Post Next Post