You are on page 1of 5

Java Programs

Contents-

Simple hello world program


Perfect number
Neon number
Class hello
{
Public static void main()
{
System.out.println(“hello world”);
}
}
import java.util.*;
class perfect
{
public static void perfect()
{
Scanner in=new Scanner(System.in);
System.out.println("Enter a number");
int n=in.nextInt();
int i=1;
int s=0;
while(i<n)
{
if(n%i==0)
s=s+i;
i++;
}
if(s==n)
System.out.println("perfect number");
else
System.out.println("not a perfect number");
}
import java.util.*;
class neon
{
public static void neon()
{
Scanner in=new Scanner(System.in);
System.out.println("Enter a number");
int n=in.nextInt();
int sq=n*n;
int s=0;
int i=sq;
while(i>0)
{
int r=i%10;
s=s+r;
i=i/10;
}
if(s==n)
System.out.println("the number is neon number");
else
System.out.println("the number is not a neon number");

You might also like