简体   繁体   English

方法 areEqualByThreeDecimalPlace(double, double) 对于 DecimalComparator 类型未定义

[英]The method areEqualByThreeDecimalPlace(double, double) is undefined for the type DecimalComparator

My main java.我的主要 java。

public class Main {
    
    DecimalComparator dc = new DecimalComparator();
    DecimalComparator rt = new DecimalComparator();
    

    public static void main(String[] args) {
        
            
        dc.areEqualByThreeDecimalPlace(1.256, 2.632);   
        
    }
    
}

My DecimalComparator code我的 DecimalComparator 代码

public class DecimalComparator {

    public  void areEqualByThreeDecimalPlace(double num1,double num2) {
        
        String Str1 = String.format("%.3g%n",num1);
        
        System.out.println("The value of Str1"+Str1);
    }

}

and in Min.class I have error "The method areEqualByThreeDecimalPlace(double, double) is undefined for the type DecimalComparator"在 Min.class 中我有错误“方法 areEqualByThreeDecimalPlace(double, double) 未定义 DecimalComparator 类型”

Your main method is static.您的main方法是 static。 You cannot get a non-static instance of DecimalComparator from a static method.您无法从 static 方法DecimalComparator的非静态实例。 You have to get an instance of your Main class to get an instance of your DecimalConverter class.您必须获取Main class 的实例才能获取DecimalConverter class 的实例。

Field names in Java always start with a lower-case character. Java 中的字段名称始终以小写字符开头。

Here's the complete runnable code I used.这是我使用的完整的可运行代码。 I made your DecimalComparator class an inner class so I could post the code as one block.我将您的DecimalComparator class 设为内部 class ,因此我可以将代码作为一个块发布。

public class DecimalComparatorMain {

    public static void main(String[] args) {
        DecimalComparatorMain dcm = new DecimalComparatorMain();
        DecimalComparator dc = dcm.new DecimalComparator();
        dc.areEqualByThreeDecimalPlace(1.256, 2.632);
    }

    public class DecimalComparator {

        public void areEqualByThreeDecimalPlace(double num1, double num2) {
            String str1 = String.format("%.3g%n", num1);
            System.out.println("The value of str1: " + str1);
        }

    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Car Anylogic 类型未定义方法 getDistanceByRoute(double, double, double, double) - The method getDistanceByRoute(double, double, double, double) is undefined for the type Car Anylogic 未定义Double类型的deposit(double)方法 - The method deposit(double) is undefined for the type Double 未为类型Loan?定义方法Loan(double,int,double)。 - The method Loan(double, int, double) is undefined for the type Loan? 对于类型为new ActionListener(){}的方法xy(double,…)未定义 - The method xy(double, …) is undefined for the type new ActionListener(){} 未为类型Math定义IEEEremainder(double,double) - IEEEremainder(double, double) is undefined for the type Math “方法Double(String)未定义”(如何转换为Double?) - “The method Double(String) is undefined” (How to cast to Double?) 如何解决 main 类型中的方法 add(double, double, int, double) 不适用于参数 (double, double, double, double) - how to solve The method add(double, double, int, double) in the type main is not applicable for the arguments (double, double, double, double) 错误:&lt; 运算符未定义参数类型 Double[], double - error: the < operator is undefined for the arguments type(s) Double[], double 对于double类型,EditText参数类型,未定义运算符* - The operator * is undefined for the argument type(s) double, EditText 运算符 += 未定义参数类型 double、Item - The operator += is undefined for the argument type(s) double, Item
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM