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

CSP008 Practical 02

Uploaded by

vt23cs90
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)
0 views

CSP008 Practical 02

Uploaded by

vt23cs90
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

2.

Develop a java program to print the prime numbers between n1 to n2 using class,
objects and methods

import java.util.Scanner;

public class PrimeNumber

public static void main(String args[])

int s1, s2, s3, flag = 0, i, j;

Scanner s = new Scanner(System.in);

System.out.println ("Enter the lower limit :");

s1 = s.nextInt();

System.out.println ("Enter the upper limit :");

s2 = s.nextInt();

System.out.println ("The prime numbers in between the entered limits are :");

for(i = s1; i <= s2; i++)

for( j = 2; j < i; j++)

if(i % j == 0)

flag = 0;

break;

else

flag = 1;
}

if(flag == 1)

System.out.println(i);

You might also like