0% found this document useful (0 votes)
9 views

Practical 7

This Java code defines a Prime class with methods to input a number, check if it is prime by dividing it by all integers from 1 to itself, and display the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Practical 7

This Java code defines a Prime class with methods to input a number, check if it is prime by dividing it by all integers from 1 to itself, and display the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

*;

import java.io.*;

class Prime

int n;

Prime()

n=0;

void input(int x)

n=x;

void display()

int c=0;

for(int i=1;i<=n;i++)

if(n%i==0)

c++;

if(c==2)

System.out.println(n+" is a Prime Number");

else

System.out.println(n+" is Not a Prime Number");

}
}

public static void main(String args[])throws IOException

Scanner in=new Scanner(System.in);

System.out.println("Enter the Number");

int no=in.nextInt();

Prime obj=new Prime();

obj.input(no);

obj.display();

You might also like