Java class program
getting 0.0 as output which is wrong import java.util.*; class Point { int x, y; Point() { x=0; y=0; } void getdata(int a, int b) { x=a; y=b; } } class Line { Point p1 = new Point(); Point p2 = new Point(); Line() { p1.x=0; p1.y=0; p2.x=0; p2.y=0; } Line(int a, int b ,int c, int d) { p1.x=a; p1.y=b; p2.x=c; p2.y=d; } double length() { double ans; ans=Math.sqrt((p2.x-p1.x)*(p2.x-p1.x)-(p2.y-p1.y)*(p2.y-p1.y)); return ans; } } class Triangle { Line l1 = new Line(); Line l2 = new Line(); Line l3 = new Line(); void perimeter() { System.out.print (l1.length()+l2.length()+l3.length()); } } class Program { public static void main(String [] args) { Scanner sc = new Scanner(System.in); Point p = new Point(); System.out.print("Enter two points\n"); int a = sc.nextInt(); int b = sc.nextInt(); p.getdata(a,b); Line l = new Line(); l.length(); Triangle t = new Triangle(); t.perimeter(); } } https://www.sololearn.com/compiler-playground/cnXOSNypDPUw