forked from DSkilton/UdemyTimBurchalka
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSharedDigit.java
More file actions
36 lines (31 loc) · 1.27 KB
/
Copy pathSharedDigit.java
File metadata and controls
36 lines (31 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.TimBuchalka;
//Write a method named hasSharedDigit with two parameters of type int. Each
//number should be within the range of 10 (inclusive) - 99 (inclusive). If one
//of the numbers is not within the range, the method should return false.
//
//The method should return true if there is a digit that appears in both
//numbers, such as 2 in 12 and 23; otherwise, the method should return false.
//
//EXAMPLE INPUT/OUTPUT:
//* hasSharedDigit(12, 23); → should return true since the digit 2 appears in both numbers
//* hasSharedDigit(9, 99); → should return false since 9 is not within the range of 10-99
//* hasSharedDigit(15, 55); → should return true since the digit 5 appears in both numbers
public class SharedDigit {
public static boolean hasSharedDigit (int a, int b) {
if(a <= 9 || a >= 99 || b <= 9 || b >= 99) {
while(a != 0){
int check = a % 10;
a /= 10;
while(b != 0 ){
if(b % 10 == check){
System.out.println("true");
return true;
}
b /= 10;
}
}
}
System.out.println("false");
return false;
}
}