forked from DHEERAJHARODE/Hacktoberfest2024-Open-source-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindingDory.java
35 lines (24 loc) · 877 Bytes
/
FindingDory.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
package loops;
import java.util.Scanner;
public class FindingDory {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
/*My friend generated a series 1 4 8 9 12 17 25 28 .... . Each element of this series is known as "Dory". Your task is to find out whether a number n is Dory or not.
NOTE: If n is "Dory", then return 1 else return 0.*/
{
int n = sc.nextInt();
double sum1 = (5*n + 4);
double k1 = Math.sqrt(sum1);
double sum2 = (5*n - 4);
double k2 = Math.sqrt(sum2);
if(((int)(sum1/k1) == k1 )||((int)(sum2/k2) == k2 ) )
{
System.out.println("The number is Dory 1" );
}
else
{
System.out.println("The number is not Dory 0" );
}
}
}
}