File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments