zoukankan      html  css  js  c++  java
  • java 导入自定义类

    eclipse导入很容易,昨天上课学了一下用记事本写java,导入自定义类,这就麻烦了。

    代码贴一下,方便操作:

    package tom.jiafei;
    
    public class SquareEquation {
        
        double a,b,c;
        double root1,root2;
        
        boolean boo;
        
        public SquareEquation (double a,double b,double c) {
            
            this.a = a;
            this.b = b;
            this.c = c;
            if(a!=0) boo = true;
            else boo = false;
        }
        
        public void setCoefficient(double a,double b,double c) {
            this.a = a;
            this.b = b;
            this.c = c;
            if(a!=0)
                boo = true;
            else boo = false;
        }
        
        public void getRoots() {
            if(boo) {
                System.out.println("shi er yuan fang chen shi");
                double disk = b*b - 4*a*c;
                if(disk>=0) {
                    root1 = (-b+Math.sqrt(disk)/(2*a));
                    root2 = (-b-Math.sqrt(disk)/(2*a));
                    System.out.println("the roots are"+root1+" "+root2);
                    
                }
                else System.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
         */
        public static void main(String[] args) {
            SquareEquation equation = new SquareEquation(4, 5, 1);
            equation.getRoots();
            equation.setCoefficient(-3, 4, 5);
            equation.getRoots();
        }
    
    }
    View Code

    直接上图:

    C盘有个求二元方程的带包的类,包名tom.jiafei,编译一下,把.class的文件放到tomjiafei目录下。

    D盘有个主函数用到这个类,先重置classpath.打一句set classpath = .....jrelib t.jar;.;C:1000

    然后修改环境变量 set classpath = ....jrelib t.jar;.;C:1000

    编译运行主函数。

    安装java,系统默认classpath =....jrelib t.jar;.;

    表示应用程序可以使用当前目录下的无名包类,和子目录下的有名包(并且对应)。

    要是应用程序要使用的类,不满足以上条件,就要重新设置classpath.加一个参数,就是包名的上一级目录。

    反过来,要是满足条件,就不必这么麻烦了,可以直接编译主函数。

  • 相关阅读:
    get the default proxy by Powershell
    import-module in $profile
    Basic Queries (LINQ to XML)
    xpath中双斜杠的作用// double slash
    Powershell 常见问题
    touch all contents in a folder recursively
    What's the difference between HEAD, working tree and index, in Git?
    beyond compare 比较文本 standard alignment VS unaligned
    bat文件中调用传参的问题
    bacth参数说明 cmd parameter
  • 原文地址:https://www.cnblogs.com/TreeDream/p/5958033.html
Copyright © 2011-2022 走看看