Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如果等于或不等于两个数字,则方法等于搜索_Java_Equals - Fatal编程技术网

Java 如果等于或不等于两个数字,则方法等于搜索

Java 如果等于或不等于两个数字,则方法等于搜索,java,equals,Java,Equals,我想在这方面帮助我。我应该创建一个方法equals来检查两个对象。如果对象相等,则返回true,否则返回false。 对我来说我一直在做这件事,但我以前用的方法与以前不同,就像那样 public static boolean trueorfalse(int cars,int bikes){ boolean y; if(get.car==get.bikes) { System.out.println("are equal"); y=true; } e

我想在这方面帮助我。我应该创建一个方法equals来检查两个对象。如果对象相等,则返回true,否则返回false。 对我来说我一直在做这件事,但我以前用的方法与以前不同,就像那样

public static boolean trueorfalse(int cars,int bikes){
   boolean y;
   if(get.car==get.bikes)
   {
    System.out.println("are equal");
    y=true;
   }
    else
   {
    System.err.println("arent equal");
    y=false;
   }
 return y;
}
现在使用相同的方法:

public static boolean equal(int cars,int bikes){  //i change the name?
       if(get.car==get.bikes)   // may needs here equalsof() something like this? or is completely wrong i am.
       {
        System.out.println("are equal");
        y=true;
       }
        else
       {
        System.err.println("arent equal");
        y=false;
       }
     return y;
    }

如果你能帮我解决这个问题,我将不胜感激,因为我想我已经解决了这个问题,但我不确定。谢谢,我想说的是,这是我第一次来这里,我不知道你是否因为是“乞丐”级别而帮不上忙。

我想说,你太接近正确了。
现在,它修好了

public static boolean equal(int cars,int bikes{
if(car==bikes)
//since you are comparing two ints, you don't require any !
{
System.out.println("are equal");
y=true;
}
else
{
System.err.println("arent equal");
/*Preferably use System.out.println().Having an inequality as this cannot be 
attributed to error. It's okay if you stick to your view.There is no hard and fast rule either !*/ 
y=false;
}
return y;
}

为什么要对int调用getter方法?为什么不把bikes==cars?为什么要传递两个int值作为参数,但不使用它们?您正在使用的
get
是什么?请提供可编译的代码。然后我们可以给你明确的答案。正如其他人提到的,没有人知道什么是
get
。传递两个整数-
int cars,int bikes
“如何检查这是否相等?”您的方法接受两个参数,
car
bike
,这两个参数都是整数,键入
int
。是否要检查
汽车
=
自行车
?或者,你是想完全做别的事情吗?什么是“两个对象”?在Java中,“对象”一词的意思是特定的东西,除非你是这个意思,否则不要使用这个词。如果您将
汽车
自行车
作为对象,请不要;将它们称为“参数”或“参数”。