24
is a sunny number because the square root of 24 + 1 = 5
is a whole number.import java.util.Scanner;
public class SunnyNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = sc.nextInt();
sc.close();
double s = Math.sqrt(n + 1);
if ((int)s == s) {
System.out.println(n + " is a sunny number.");
} else {
System.out.println(n + " is not a sunny number.");
}
}
}
Enter a number: 24
24 is a sunny number.
Enter a number: 27
27 is not a sunny number.