Showing posts with label Neon Number. Show all posts
Showing posts with label Neon Number. Show all posts

Neon Number

Neon Number is a positive integer, which is equal to the sum of the digits of its square. For example, 9 is a neon number, because 92 = 81, and the sum of the digits 8 + 1 = 9, which is same as the original number.

 import java.util.*;

class neon

{//class neon opens

    public static void main(String[]args)

    {//main method opens

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter a no");

        int n=sc.nextInt();//variable n to accept the no

        int sq=n*n;//varible sq to store the square of the no

        int r=0,s=0;//variable r to extract the digits,variable s to store the sum

        while(sq>0)

        {

            r=sq%10;

            s=s+r;

            sq=sq/10;

        }

        if(s==n)

        System.out.println(n+" is a neon no");

        else

        System.out.println(n+" is not a neon no");

    }//main method closes

}//class closes


Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...