Write a java program to input 2 numbers and find the difference without comparing them by using relational operator.
Share
Write a java program to input 2 numbers and find the difference without comparing them by using relational operator.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Required Answer :
Question:
Program:
This is the required Java program for the question.
public class Relation
{
public static void main(String args[])
{
int a=20;
int b=30;
System.out.println("a == b =" + (a == b));
System.out.println("a != b =" + (a != b));
System.out.println("a > b =" + (a > b));
System.out.println("a < b =" + (a < b ));
System.out.println("b >= a =" + (b >= a));
System.out.println("b <= a =" + (b <= a));
}
}
The output will be as follows:
a == b = false
a ! = b = true
a > b = false
a < b = true
b >= a = true
b <= a = false.
Verified answer
Answer:
public class RelationalDemo {
public static void main(String[] args) {
//a few numbers
int i = 37;
int j = 42;
int k = 42;
System.out.println("Variable values...");
System.out.println(" i = " + i);
System.out.println(" j = " + j);
System.out.println(" k = " + k);
//greater than
System.out.println("Greater than...");
System.out.println(" i > j = " + (i > j)); //false
System.out.println(" j > i = " + (j > i)); //true
System.out.println(" k > j = " + (k > j)); //false;
//they are equal
//greater than or equal to
System.out.println("Greater than or equal to...");
System.out.println(" i >= j = " + (i >= j)); //false
System.out.println(" j >= i = " + (j >= i)); //true
System.out.println(" k >= j = " + (k >= j)); //true
//less than
System.out.println("Less than...");
System.out.println(" i < j = " + (i < j)); //true
System.out.println(" j < i = " + (j < i)); //false
System.out.println(" k < j = " + (k < j)); //false
//less than or equal to
System.out.println("Less than or equal to...");
System.out.println(" i <= j = " + (i <= j)); //true
System.out.println(" j <= i = " + (j <= i)); //false
System.out.println(" k <= j = " + (k <= j)); //true
//equal to
System.out.println("Equal to...");
System.out.println(" i == j = " + (i == j)); //false
System.out.println(" k == j = " + (k == j)); //true
//not equal to
System.out.println("Not equal to...");
System.out.println(" i != j = " + (i != j)); //true
System.out.println(" k != j = " + (k != j)); //false
}
}
pls mark me as brainliest....