Eclipse import is easy, yesterday in class learned to write Java with Notepad, import custom classes, which is troublesome.
Code paste, easy to operate:
PackageTom.jiafei; Public classsquareequation {DoubleA,b,c; DoubleRoot1,root2; BooleanBoo; PublicSquareequation (DoubleADoubleBDoublec) { This. A =A; This. B =b; This. C =C; if(a!=0) Boo =true; ElseBoo =false; } Public voidSetcoefficient (DoubleADoubleBDoublec) { This. A =A; This. B =b; This. C =C; if(a!=0) Boo=true; ElseBoo =false; } Public voidgetroots () {if(Boo) {System.out.println ("Shi er yuan Fang Chen Shi"); DoubleDisk = b*b-4*a*C; if(disk>=0) {root1= (-b+math.sqrt (disk)/(a)); Root2= (-b-math.sqrt (disk)/(a)); System.out.println ("The Roots is" +root1+ "" +Root2); } ElseSystem.out.println ("Mei You Jie"); } Else{System.out.println ("Bu shi er yuan fang Chen Shi Gen"); } } }View Code
import tom.jiafei.*; Public class SunRise { /** @param args * / Publicstaticvoid main (string[] args) { new squareequation (4 , 5, 1); Equation.getroots (); Equation.setcoefficient (-3, 4, 5); Equation.getroots (); }}
View Code
Direct:
C Disk has a two-yuan equation of the packet class, package name Tom.jiafei, compile, put the. class file into the Tom\jiafei directory.
D disk has a main function to use this class, first reset Classpath. hit a set classpath = .... \jre\lib\rt.jar;.; C:\1000
Then modify the environment variable set classpath = .... \jre\lib\rt.jar;.; C:\1000
Compile and run the main function.
Install Java, system default Classpath =....\jre\lib\rt.jar;.;
Indicates that the application can use the Nameless package class under the current directory, and the named Package (and corresponding) under the subdirectory.
If the application is to use a class that does not meet the above criteria, it is necessary to reset the classpath. Add a parameter, which is the top-level directory of the package name.
Conversely, if you meet the conditions, you don't have to be so troublesome, you can compile the main function directly.
Java import custom class