Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ch6ex1b;
- import java.util.Scanner;
- public class Ch6Ex1b
- {
- public static void main(String[] args)
- {
- Scanner sc=new Scanner(System.in);
- System.out.print("Enter a number: ");
- int num=sc.nextInt();
- System.out.print("Enter another number: ");
- int num2=sc.nextInt();
- boolean isPrime;
- if(num2<num)
- {
- int temp=num2;
- num2=num;
- num=temp;
- }
- System.out.println("Prime numbers between "+num+" and "+num2+" are: ");
- num+=1;
- num2-=1;
- for(int c=num;c<=num2;c++)
- {
- isPrime=true;
- if(c<2)isPrime=false;
- else for(int x=2;x<c;x++)if(c%x==0)isPrime=false;
- if(isPrime)System.out.println(c);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment