Monday, 3 November 2014

A program accepts two integers as command line arguments. It displays all prime numbers between these two. Using assertions, validate the input for the following criteria: Both should be positive integers. The second should be larger than the first.




Name : Shreyal Mandot

Title : 2. A program accepts two integers as command line arguments. It displays all prime numbers between these two. Using assertions, validate the input for the following criteria: Both should be positive integers. The second should be larger than the first.



class ass4a2
{

public static void main(String args[])
{

int a,b;

a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);

boolean c=(a>=0 && b>=0 && b>a);

assert c :"Criteria Not Satisfied";

System.out.println("Prime no's between "+a+" & "+b);

for(int i=a;i<=b;i++)
{

if(i==2 || i==3 || i ==5 || i==7)
System.out.println("\n "+i);

else
{

if(i%2 !=0 && i%3 !=0 && i%5!=0 && i%7!=0)
System.out.println("\n "+i );

}

}

}

}

/*

Output-

[prady@localhost setA]$ javac ass4a2.java
[prady@localhost setA]$ java ass4a2 12 23

Prime no's between 12 & 23

 13

 17

 19

 23

java ass4a2 12 10

Exception in thread "main" java.lang.AssertionError: Criteria Not Satisfied
   at ass4a2.main(ass4a2.java:16)
[prady@localhost setA]$

*/

No comments:

Post a Comment