Creating and importing packages in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Creating and importing packages in java

One package contains an interface and another package must implement that interface, can anyone tell me the way to import,(because simply import does not work)

27th Jan 2019, 1:45 PM
jahnavi mantripragada
jahnavi mantripragada - avatar
4 Answers
+ 2
package Quad2; import java.util.*; import Quard1.*; class Quadratic_equation implements Quard1.Quadratic_Eq{ public static void roots(){ System.out.println("Enter the a,b,c of ax^2+bx+c :"); Scanner scan = new Scanner(System.in); double x[]=new double[3]; for(int i=2;i>=0;i--) { System.out.print("x^"+i+":"); x[i]=scan.nextDouble(); } if(Math.pow(x[1],2.0)-(4*x[2]*x[0])>=0){ double root1 = (0-x[1]+Math.sqrt(Math.pow(x[1],2.0)-(4*x[2]*x[0])))/(2*x[2]); double root2 = (0-x[1]-Math.sqrt(Math.pow(x[1],2.0)-(4*x[2]*x[0])))/(2*x[2]); System.out.println("Root1: "+root1+"\nRoot2: "+root2);} else{ double real,imag; real=(0-x[1])/(2*x[2]); imag=Math.sqrt(Math.abs(Math.pow(x[1],2.0)-(4*x[2]*x[0])))/(2*x[2]); System.out.println("Root1: "+real+"+i"+imag+"\nRoot2:"+real+"-i"+imag); } } public static void main(String args[]){     Quadratic_equation Q = new Quadratic_equation();     Q.roots(); } }
27th Jan 2019, 1:54 PM
jahnavi mantripragada
jahnavi mantripragada - avatar
+ 1
package Quad1; interface Quadratic_Eq{ public static void roots(){ } }
27th Jan 2019, 1:55 PM
jahnavi mantripragada
jahnavi mantripragada - avatar
+ 1
This is the code
27th Jan 2019, 1:55 PM
jahnavi mantripragada
jahnavi mantripragada - avatar
+ 1
If anyone figures out an error please do tell me
27th Jan 2019, 1:55 PM
jahnavi mantripragada
jahnavi mantripragada - avatar