-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path3.2 Number divisible by N.java
55 lines (41 loc) · 1.23 KB
/
3.2 Number divisible by N.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
/*
Peter asked his friend Max to implement a Java program in which 3 integers X, Y and N are given as a runtime input and all the numbers between X and Y which are divisible by N must be displayed on console. If no such number is possible for the given input then, print NO OUTPUT.
Input Format
3 space separated integers X, Y and N
Constraints
X, Y and N are less than 1000
X and Y are positive integers and X < Y
Output Format
All the integers between X and Y separated by space which are divisible by N
Sample Input 0
6 11 3
Sample Output 0
6 9
Sample Input 1
2 6 2
Sample Output 1
2 4 6
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc =new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
int n = sc.nextInt();
boolean check = false;
for(int i=x;i<=y;i++)
{
if(i%n == 0){
System.out.print(i+" ");
check =true;
}
}
if(check == false)
{
System.out.print("NO OUTPUT");
}
}
}