Computer Science, asked by priyanka14, 1 year ago

give an example of constructor program of java

Answers

Answered by viruvir30201
1
ok bro i will give you the examples by the comments!!


Answered by Anonymous
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");

}

}
Similar questions