in this program this logic is used
if(Math.abs(num1-num2)<=0)
{
System.out.println("numbers are same");
}
else
{System.out.println("numbers are different");
}
please explian me how this logic will work for this asked condition in the question
Instructor
Yogesh Chawla Replied on 11/04/2024
public class Class1 {
public static void main(String[] args) {
Class1 obj = new Class1();
System.out.println(obj.diff(-5, 5)); // Actual Output is -10 but abs made it to 10
}
int diff(int num1, int num2) {
return Math.abs(num1 - num2);
}
}
package com.programming.class1;
public class Class2{
public static void main(String[] args) {
show();
}
static void show() {
int num1 = 10, num2 = 19;
System.out.println(Math.abs(num1-num2));
//Actual Output is -9 but abs made to 9
//that's the reason 9<0 failed and else will run
if(Math.abs(num1-num2)<=0){
System.out.println("numbers are same");
}
else{
System.out.println("numbers are different");
}
}
}