• Post Reply Bookmark Topic Watch Topic
  • New Topic

Assertion error  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//please see the following program..It compiles properly but it gives an assertion error..
import java.io.*;
class cal
{
public int n;
public int fact(int n)
{
if (n==0)
{
return 1;
}
else
{
return fact(n-1)*n;
}
}
}
public class Factorial
{
public static void main(String[] args)
{
cal c=new cal();
DataInputStream d=new DataInputStream(System.in);
System.out.print("Enter the Value:");
try
{
c.n=Integer.parseInt(d.readLine());
}
catch(IOException ie){System.out.println(ie);}
System.out.println("Factorial: "+ c.fact(c.n));
}
}
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works fine. I don't see any error. can u post the error and the JDK used?
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi priya,

the program what u have given is working fine except it says deprecated problems. since you are using readLine method which is a deprecated one
i dont find any other problems.

one important thing priya, i the program i dont see where you are checking the number entered, i know you are using assert to check if somebody enters negative number. but where is the assertion statement in program. plz do check once again and revert back to me. ok .

Have a nice day,
Good Guy
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!