Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

hi

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic