• Post Reply Bookmark Topic Watch Topic
  • New Topic

hi  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will post that assertion error also
for this program
please see after this program
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));
}
}


I saved the program in jdk1.3.1\bin and I tried to compile..It gives "depreciated API"
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

You are getting that error because readline API is deprecated for DataInputStream class.

Quoting the 1.4.2 documentation :

readLine

public final String readLine()
throws IOException

Deprecated. This method does not properly convert bytes to characters. As of JDK 1.1, the preferred way to read lines of text is via the BufferedReader.readLine() method. Programs that use the DataInputStream class to read lines can be converted to use the BufferedReader class by replacing code of the form:

DataInputStream d = new DataInputStream(in);


with:

BufferedReader d
= new BufferedReader(new InputStreamReader(in));


I guess you can cross-verify this with the 1.3 documentation as well. Though I am not sure as to why this is being shown as an error. Deprecations are generally displayed as warnings.

Hope this helps...

[ April 19, 2005: Message edited by: Ashish Chopra ]
[ April 19, 2005: Message edited by: Ashish Chopra ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!