Sunday, June 21, 2020

Write a program to input a number and check whether it is Sunny Number or not?(24 , 24+1=25 is a perfect square, so 24 is a sunny number)

24)  Write a program to input a number and check whether it is Sunny Number or not?(24 , 24+1=25 is a perfect square, so 24 is a sunny number)

import java.util.*;
public class Sunny_number
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        double a = sc.nextInt();
        double p = a+1;
        double b = Math.sqrt(p);
        int c = (int)b;
        if(b==c)
        {
            System.out.println(a+" is a SUNNY number");
        }
        else
        {
             System.out.println(a+" is not a SUNNY number");
        } 
    }
}

3 comments:

if you have any doubts, Please let me know.
Your Truly
Shashank Porwal

 jhvghvgk ;nkjn ,nkjhj