-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCognizant_Q14.java
More file actions
50 lines (37 loc) · 1017 Bytes
/
Cognizant_Q14.java
File metadata and controls
50 lines (37 loc) · 1017 Bytes
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
package technical;
/* Bela teaches her daughter to find the factors of a given number. When she provides a number to her daughter, she should tell the factors of that number. Help her to do this, by writing a program. Write a class FindFactor.java and write the main method in it.
Note :
If the input provided is negative, ignore the sign and provide the output. If the input is zero
If the input is zero the output should be “No Factors”.
Sample Input 1 :
54
Sample Output 1 :
1, 2, 3, 6, 9, 18, 27, 54
Sample Input 2 :
-1869
Sample Output 2 :
1, 3, 7, 21, 89, 267, 623, 1869*/
import java.util.*;
public class Cogni14 {
static void Fact(int a)
{
if (a==0)
System.out.println("No Factors");
else
{
a=Math.abs(a);
for(int i=1;i<a;i++)
{
if (a%i==0)
System.out.print(i+",");
}
System.out.print(a);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number ");
int a =sc.nextInt();
Fact(a);
}
}