write a program to find neon number between 10 to 10000 in Java
QGP:
Can you define a Neon Number?
Answers
Answered by
9
/* To check whether a number is 'Neon'. */
/* A number is said to be Neon if the sum of digits of square of the given number is equal to the number itself */
import java.io.*;
public class Neon_Number
{
public static void main(String args[]) throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
long n,s,d,sum;
int f=1;
System.out.println(" A number is said to be 'Neon' if the sum of digits of square of the given number is equal to the number itself ");
System.out.println(" There are only three Neon numbers: 0, 1 and 9 .");
System.out.println();
while (f==1)
{
sum=0;
System.out.print("Enter a number: ");
n = Long.parseLong(in.readLine());
s=n*n;
do
{
d=s%10;
sum+=d;
s=s/10;
}
while(s!=0);
if (sum==n)
System.out.println(n+" is a Neon number");
else
System.out.println(n+" is not a Neon number");
System.out.println();
System.out.print("Enter 1 to repeat, 0 to exit: ");
f = Integer.parseInt(in.readLine());
System.out.println();
}
System.out.println();
System.out.println("Program ends.");
}
}
/* A number is said to be Neon if the sum of digits of square of the given number is equal to the number itself */
import java.io.*;
public class Neon_Number
{
public static void main(String args[]) throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
long n,s,d,sum;
int f=1;
System.out.println(" A number is said to be 'Neon' if the sum of digits of square of the given number is equal to the number itself ");
System.out.println(" There are only three Neon numbers: 0, 1 and 9 .");
System.out.println();
while (f==1)
{
sum=0;
System.out.print("Enter a number: ");
n = Long.parseLong(in.readLine());
s=n*n;
do
{
d=s%10;
sum+=d;
s=s/10;
}
while(s!=0);
if (sum==n)
System.out.println(n+" is a Neon number");
else
System.out.println(n+" is not a Neon number");
System.out.println();
System.out.print("Enter 1 to repeat, 0 to exit: ");
f = Integer.parseInt(in.readLine());
System.out.println();
}
System.out.println();
System.out.println("Program ends.");
}
}
Answered by
6
class Neon
{
//program to check whether the number is neon or not
int sq,d,sd=0;
System.out.println ("the neon numbers are ");
for(int i=10;i <=10000;i++)
{
sq=i*i;
while (sq!=0)
{
d=sq%10
sd = sd+d;
sq/=10;
}
if (sd==i)
{
System.out.println(i+" , ");
}
sd=0;
}//for loop closed
}//main
}
variable description for convenience :-
__________________________________
i - as a loop variable for numbers from
10 to 1000.
sq = to store the value of square of numbers
d = for the digits of the square
sd = sum of the digits of square
{
//program to check whether the number is neon or not
int sq,d,sd=0;
System.out.println ("the neon numbers are ");
for(int i=10;i <=10000;i++)
{
sq=i*i;
while (sq!=0)
{
d=sq%10
sd = sd+d;
sq/=10;
}
if (sd==i)
{
System.out.println(i+" , ");
}
sd=0;
}//for loop closed
}//main
}
variable description for convenience :-
__________________________________
i - as a loop variable for numbers from
10 to 1000.
sq = to store the value of square of numbers
d = for the digits of the square
sd = sum of the digits of square
Similar questions