Skip to content

Commit 9dda5aa

Browse files
authored
Merge pull request #34 from aarush2410/main
sunny
2 parents 387313e + 7513bb0 commit 9dda5aa

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

sunny.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java.util.*;
2+
public class SunnyNumberExample1
3+
{
4+
//driver code
5+
public static void main(String args[])
6+
{
7+
Scanner sc = new Scanner(System.in);
8+
System.out.print("Enter a number to check: ");
9+
//reading a number from the user
10+
int N=sc.nextInt();
11+
//calling user-defined function
12+
isSunnyNumber(N);
13+
}
14+
//function checks whether the given is a perfect square or not
15+
static boolean findPerfectSquare(double num)
16+
{
17+
//finds the square root of the ggiven number
18+
double square_root = Math.sqrt(num);
19+
//if square root is an integer
20+
return((square_root - Math.floor(square_root)) == 0);
21+
}
22+
//function that checks whether the given number is Sunny or not
23+
static void isSunnyNumber(int N)
24+
{
25+
//checks N+1 is perfect square or not
26+
if (findPerfectSquare(N + 1))
27+
{
28+
System.out.println("The given number is a sunny number.");
29+
}
30+
//executes if N+1 is not a perfect square
31+
else
32+
{
33+
System.out.println("The given number is not a sunny number.");
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)