Skip to main content

Write a Java program that accepts four integers from the user and prints equal if all four are equal, and not equal otherwise.

 CODE:


import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        

        // Accepting four integers from the user

        System.out.println("Enter the first integer:");

        int num1 = scanner.nextInt();

        

        System.out.println("Enter the second integer:");

        int num2 = scanner.nextInt();

        

        System.out.println("Enter the third integer:");

        int num3 = scanner.nextInt();

        

        System.out.println("Enter the fourth integer:");

        int num4 = scanner.nextInt();

        

        // Checking if all four integers are equal

        if (num1 == num2 && num2 == num3 && num3 == num4) {

            System.out.println("Equal");

        } else {

            System.out.println("Not Equal");

        }

        

        scanner.close();

    }

}


Algorithm:
  1. Import the Scanner class to read input from the user.
  2. Define a class named Main.
  3. Define the main method, which is the entry point of the program.
  4. Create a Scanner object named scanner to read input from the user.
  5. Prompt the user to enter the first integer.
  6. Read the first integer entered by the user and store it in the variable num1.
  7. Prompt the user to enter the second integer.
  8. Read the second integer entered by the user and store it in the variable num2.
  9. Prompt the user to enter the third integer.
  10. Read the third integer entered by the user and store it in the variable num3.
  11. Prompt the user to enter the fourth integer.
  12. Read the fourth integer entered by the user and store it in the variable num4.
  13. Check if all four integers (num1, num2, num3, num4) are equal using the logical AND (&&) operator.
  14. If all four integers are equal, print "Equal".
  15. If not all four integers are equal, print "Not Equal".
  16. Close the Scanner object to release system resources.
  17. End of the program.










Popular posts from this blog

krushnaaa

  import java . awt .* ; import java . awt . event .* ; public class SimpleAWTExample {     public static void main ( String [] args ) {         // Create a Frame         Frame frame = new Frame ( "Simple AWT Example" );         // Create a Button         Button button = new Button ( "Click Me!" );         // Set layout for the Frame         frame . setLayout ( new FlowLayout ());         // Add the Button to the Frame         frame . add ( button );         // Set size of the Frame         frame . setSize ( 300 , 200 ); // Width: 300 pixels, Height: 200 pixels         // Make the Frame visible         frame . setVisible ( true );         // Add a WindowListener to handle closing event     ...

Write a program to create a class Student2 along with two method getData (), printData () to get the value through argument and display the data in printData. Create the two objects s1, s2 to declare and access the values from class STtest.

 CODE: import java.util.Scanner; class Student2 {     private String name;     private int age;          // Method to set data     public void getData(String name, int age) {         this.name = name;         this.age = age;     }          // Method to print data     public void printData() {         System.out.println("Name: " + name);         System.out.println("Age: " + age);     } } public class STtest {     public static void main(String[] args) {         Scanner scanner = new Scanner(System.in);                  // Creating objects of Student2 class         Student2 s1 = new Student2();         Student2 s2 = new Student2();              ...

Create an in-order threaded binary search tree and perform the traversals.(Double Thread)

 CODE: #include <iostream> using namespace std; struct Node {     int data;     Node* left;     Node* right;     bool leftThread;     bool rightThread; }; Node* createThreadedBST(int arr[], int n) {     Node* root = nullptr;     for (int i = 0; i < n; ++i) {         Node* newNode = new Node;         newNode->data = arr[i];         newNode->left = newNode->right = nullptr;         newNode->leftThread = newNode->rightThread = true;         if (root == nullptr) {             root = newNode;         } else {             Node* current = root;             Node* parent = nullptr;             while (true) {                ...