-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfactor nth.java
41 lines (40 loc) · 944 Bytes
/
factor nth.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
import java.io.*;
import java.util.*;
class factor
{
public static void main(String args[])
{
try
{
Scanner sc=new Scanner(System.in);
int count=0,n=100,i,j=0,N;
int []a=new int [10];
System.out.println("Enter the number:");
n=sc.nextInt();
System.out.println("Enter the value of N:");
N=sc.nextInt();
if(n<=0)
{
System.out.println("Enter valid number");
}
else
{
for(i=1;i<=n;i++)
{
if(n%i==0)
{
a[j] = i;
count++;
j++;
}
}
System.out.println("The number of factors:"+count);
System.out.println(N + " th factor " + a[N-1]);
}
}
catch(Exception e)
{
System.out.println("Enter only numbers");
}
}
}