• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Assertion error

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic