give an example of constructor program of java
Answers
Answered by
1
ok bro i will give you the examples by the comments!!
Answered by
0
HEY MATE HERE IS YOUR ANSWER...
//To check whether a number is prime or not
public class Prime
{
int n;
Prime( )
{
n=0;
}
void input(int x)
{
n=x;
}
void display( )
{
int i,c=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
c=c+1;
}
if(c==2)
System.out.println(n +"is a prime number");
else
System.out.println(n +"is not a prime number");
}
}
//To check whether a number is prime or not
public class Prime
{
int n;
Prime( )
{
n=0;
}
void input(int x)
{
n=x;
}
void display( )
{
int i,c=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
c=c+1;
}
if(c==2)
System.out.println(n +"is a prime number");
else
System.out.println(n +"is not a prime number");
}
}
Similar questions