JAVA PROGRAM TO DEMONSTRATE THE PALINDROME PROGROM USING CLASSES AND OBJECT.

 


// JAVA PROGRAM TO DEMONSTRATE THE PALINDROME PROGROM USING CLASSES AND OBJECT.

class PalindromeExample {
    public static void main(String args[]) {
        int remainder, reversedNumber = 0, originalNumber;  // Declare variables for storing digits
       
        int numberToCheck = 454;  // The number to be checked for palindrome
       
        originalNumber = numberToCheck;  // Store the original number for later comparison
       
        // Reverse the digits of the number
        while (numberToCheck > 0) {
            remainder = numberToCheck % 10;  // Extract the last digit
            reversedNumber = (reversedNumber * 10) + remainder;  // Build the reversed number
            numberToCheck = numberToCheck / 10;  // Remove the last digit
        }
       
        // Check if the reversed number is equal to the original number
        if (originalNumber == reversedNumber) {
            System.out.println("The number is a palindrome.");  // Print if it's a palindrome
        } else {
            System.out.println("The number is not a palindrome.");  // Print if it's not a palindrome
        }
    }
}

OUTPUT:-

palindrome number

Explanation of the code:


  • The code defines a class named PalindromeExample.

  • Inside the class, there's the main method which serves as the entry point of the program.

  • The program aims to check whether a given number (n initialized as 454) is a palindrome or not. A palindrome is a number that reads the same forwards and backwards.

  • temp is used to store the original number so that we can compare it with the reversed number later.

  • The while loop runs as long as the value of n is greater than 0. It extracts the last digit of n using the modulo operator %, adds it to the reverse (sum), and then removes the last digit from n by dividing it by 10.

  • The reversed number is built digit by digit in the sum variable. For example, if n is 454, then sum becomes 010 + 4 = 4, then 410 + 5 = 45, then 45*10 + 4 = 454, which is the reverse of the original number.

  • After the loop completes, the code checks whether the original number (temp) is equal to the reversed number (sum). If they are equal, the number is a palindrome and the program prints "palindrome number". If they are not equal, the number is not a palindrome and the program prints "not palindrome".

  • In this specific example, since the original number (454) is the same as its reversed version (454), the program will print "palindrome number".




Gemini


2.0 Flash


Conversation with Gemini


I want to create this using react map function




Okay, I can definitely help you visualize how to create that filtering UI in React using the map function!


Let's break down each section (Material, Size/Diameter, etc.) and see how you could structure the React code.


JavaScript


import React from 'react';


const FilterSection = ({ title, options, onCheckboxChange }) => {

  return (

    <div>

      <h3>{title}</h3>

      {options.map((option) => (

        <div key={option.value}>

          <input

            type="checkbox"

            id={option.value}

            name={title}

            value={option.value}

            checked={option.isSelected}

            onChange={onCheckboxChange}

          />

          <label htmlFor={option.value}>{option.label}</label>

        </div>

      ))}

    </div>

  );

};


const FilterUI = () => {

  const filterData = [

    {

      title: 'Material',

      options: [

        { value: 'stainless_steel', label: 'Stainless steel', isSelected: true },

        { value: 'alloy', label: 'Alloy', isSelected: true },

        { value: 'ms', label: 'MS', isSelected: true },

        { value: 'ss', label: 'SS', isSelected: false },

        { value: 'cast_iron', label: 'Cast Iron', isSelected: false },

      ],

    },

    {

      title: 'Size/Diameter',

      options: [

        { value: '0.5_inch', label: '0.5 inch', isSelected: true },

        { value: '0.75_inch', label: '0.75 inch', isSelected: false },

        { value: '2_inches', label: '2 inches', isSelected: false },

        { value: '3_inches', label: '3 inches', isSelected: false },

        { value: '7_inches', label: '7 inches', isSelected: false },

      ],

    },

    {

      title: 'Connector Type',

      options: [

        { value: 'adapter', label: 'Adapter', isSelected: true },

        { value: 'coupling', label: 'Coupling', isSelected: false },

        { value: 'elbow', label: 'Elbow', isSelected: false },

        { value: 'reducer', label: 'Reducer', isSelected: false },

        { value: 'bushing', label: 'Bushing', isSelected: false },

      ],

    },

    {

      title: 'Exterior Finish',

      options: [

        { value: 'alloy_steel', label: 'Alloy Steel', isSelected: false },

        { value: 'aluminum', label: 'Aluminum', isSelected: false },

        { value: 'bronze', label: 'Bronze', isSelected: false },

        { value: 'copper', label: 'Copper', isSelected: false },

        { value: 'stainless_steel', label: 'Stainless Steel', isSelected: false },

      ],

    },

    {

      title: 'Usage/Application',

      options: [

        { value: 'plumbing_pipe', label: 'Plumbing Pipe', isSelected: false },

        { value: 'gas_pipe', label: 'Gas Pipe', isSelected: false },

        { value: 'chemical_handling_pipe', label: 'Chemical Handling Pipe', isSelected: false },

        { value: 'oil_gas_drilling', label: 'Oil/gas drilling', isSelected: false },

      ],

    },

  ];


Okay, I can definitely help you visualize how to create that filtering UI in React using the map function!

Let's break down each section (Material, Size/Diameter, etc.) and see how you could structure the React code.

JavaScript
import React from 'react';

const FilterSection = ({ title, options, onCheckboxChange }) => {
  return (
    <div>
      <h3>{title}</h3>
      {options.map((option) => (
        <div key={option.value}>
          <input
            type="checkbox"
            id={option.value}
            name={title}
            value={option.value}
            checked={option.isSelected}
            onChange={onCheckboxChange}
          />
          <label htmlFor={option.value}>{option.label}</label>
        </div>
      ))}
    </div>
  );
};

const FilterUI = () => {
  const filterData = [
    {
      title: 'Material',
      options: [
        { value: 'stainless_steel', label: 'Stainless steel', isSelected: true },
        { value: 'alloy', label: 'Alloy', isSelected: true },
        { value: 'ms', label: 'MS', isSelected: true },
        { value: 'ss', label: 'SS', isSelected: false },
        { value: 'cast_iron', label: 'Cast Iron', isSelected: false },
      ],
    },
    {
      title: 'Size/Diameter',
      options: [
        { value: '0.5_inch', label: '0.5 inch', isSelected: true },
        { value: '0.75_inch', label: '0.75 inch', isSelected: false },
        { value: '2_inches', label: '2 inches', isSelected: false },
        { value: '3_inches', label: '3 inches', isSelected: false },
        { value: '7_inches', label: '7 inches', isSelected: false },
      ],
    },
    {
      title: 'Connector Type',
      options: [
        { value: 'adapter', label: 'Adapter', isSelected: true },
        { value: 'coupling', label: 'Coupling', isSelected: false },
        { value: 'elbow', label: 'Elbow', isSelected: false },
        { value: 'reducer', label: 'Reducer', isSelected: false },
        { value: 'bushing', label: 'Bushing', isSelected: false },
      ],
    },
    {
      title: 'Exterior Finish',
      options: [
        { value: 'alloy_steel', label: 'Alloy Steel', isSelected: false },
        { value: 'aluminum', label: 'Aluminum', isSelected: false },
        { value: 'bronze', label: 'Bronze', isSelected: false },
        { value: 'copper', label: 'Copper', isSelected: false },
        { value: 'stainless_steel', label: 'Stainless Steel', isSelected: false },
      ],
    },
    {
      title: 'Usage/Application',
      options: [
        { value: 'plumbing_pipe', label: 'Plumbing Pipe', isSelected: false },
        { value: 'gas_pipe', label: 'Gas Pipe', isSelected: false },
        { value: 'chemical_handling_pipe', label: 'Chemical Handling Pipe', isSelected: false },
        { value: 'oil_gas_drilling', label: 'Oil/gas drilling', isSelected: false },
      ],
    },
  ];



















const FilterUI = () => {

  const filterData = [

    // ... your filterData array

  ];


  const handleCheckboxChange = (event) => {

    const { name, value, checked } = event.target;

    console.log(`Category: ${name}, Value: ${value}, Checked: ${checked}`);

  };


  return (

    <div>

      <h2>Filter Options</h2>

      {filterData.map((section) => (

        <div key={section.title}>

          <h3>{section.title}</h3>

          {section.options.map((option) => (

            <div key={option.value}>

              <input

                type="checkbox"

                id={option.value}

                name={section.title}

                value={option.value}

                checked={option.isSelected}

                onChange={handleCheckboxChange}

              />

              <label htmlFor={option.value}>{option.label}</label>

            </div>

          ))}

        </div>

      ))}

    </div>

  );

};



Tags

Post a Comment

1 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
  1. Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:111.0) Gecko/20100101 Firefox/111.0

    ReplyDelete