-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCognizant_Q10.java
56 lines (43 loc) · 1.25 KB
/
Cognizant_Q10.java
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package technical;
/*Problem Statement – Chaman planned to choose a four digit lucky number for his car. His lucky numbers are 3,5 and 7. Help him find the number, whose sum is divisible by 3 or 5 or 7. Provide a valid car number, Fails to provide a valid input then display that number is not a valid car number.
Note : The input other than 4 digit positive number[includes negative and 0] is considered as invalid.
Refer the samples, to read and display the data.
Sample Input 1:
Enter the car no:1234
Sample Output 1:
Lucky Number
Sample Input 2:
Enter the car no:1214
Sample Output 2:
Sorry its not my lucky number
Sample Input 3:
Enter the car no:14
Sample Output 3:
14 is not a valid car number*/
import java.util.*;
public class Cogni10 {
static void Check(int a)
{
if(a>=1000 && a<=9999)
{
int sum=0;
while(a!=0)
{
sum=sum+a%10;
a=a/10;
}
if(sum%3==0 || sum%5==0 || sum%7==0)
System.out.println("A Lucky Number");
else
System.out.println("Its not my lucky number");
}
else
System.out.println(a+"is not a valid car number");
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the car number: ");
int a =sc.nextInt();
Check(a);
}
}