-3

Finding area and perimeter of a triangle using stream in java.

On Compiling the below program shows

Note: triangle.java uses or overrides a deprecated API. Recompile with -Xlint:deprecation for details.

Please find what error in this program!

import java.io.*;
class triangle
{
    double s,h,area,perimeter;

    void get()throws IOException
    {
        System.out.println("Enter value of side of an equilateral triangle");
        DataInputStream dis=new DataInputStream(System.in);
        s=Double.parseDouble(dis.readLine());
        System.out.println("Enter height");
        h=Double.parseDouble(dis.readLine());
    }
    void area()
    {
        area=0.5*s*h;
    }
    void perimeter()
    {
        perimeter=3*s;
    }
    void display()
    {
        System.out.println("Area="+area);
        System.out.println("Perimeter="+perimeter);
    }
    public static void main(String args[])throws IOException
    {
        triangle t=new triangle();
        t.get();
        t.area();
        t.perimeter();
        t.display();
    }
}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Vikraman
  • 21
  • 5

2 Answers2

2

When you bring together all the information the compiler gives you, it's clear that your code "uses or overrides a deprecated API."

As you say in your most recent comment, when you do as suggested and add the additional options to the command line it tells you where the problems come from.

In this case it's DataInputStream#readLine().

Sure, you can suppress the warnings but the link explains:

"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..."

That's probably better advice than ignoring the deprecation and potential errors.

ChiefTwoPencils
  • 13,548
  • 8
  • 49
  • 75
-2

You are using readline() with DataInputStream which is deprecated in Java now. No problem with that. It is just a warning from Java community that this method may not work properly. You can suppress those warnings using

@SuppressWarnings( "deprecation" )

before the get() method.

Senthil Vidhiyakar
  • 182
  • 1
  • 2
  • 9