In the previous blog we saw how to swap two numbers .Now we will see whether two numbers are equal .
To check whether two numbers are equal
import java.io.*;
import java.util.*;
public class equal{
public static void main (String [] args)
{
int number1,number2,temp;
System.out.println("Enter two numbers:");
Scanner sc =new Scanner(System.in);
number1=sc.nextInt();
number2=sc.nextInt();
System.out.println(number1==number2);
}
}
Algorithm:-
1.Start
2.Use the int datatype for the variables number1 and number 2.
3.Use the print statement to display the text "Enter two numbers".
4.Use a scanner class to get input of the numbers.
5.In print statement use a equality operator to display the output.
Explanation:-Displays true if they are equal .If not displays false.
6.Stop
Screenshot:-
1.Code Screenshot:-
2.Output Screenshot:-
In next blog we will see how to check if two numbers are not equal.
0 Comments