Coder Social home page Coder Social logo

kavididesilva / balancebracket Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 3 KB

Challenge 2. This Java program checks whether a given string of brackets is balanced or not using a stack data structure. It defines a function called "isValid" that returns true if the brackets are balanced and false otherwise. The program compares opening and closing brackets and returns the result based on the stack's status.

Java 100.00%
algorithms-and-data-structures balanced-brackets java stack string-manipulation

balancebracket's Introduction

BalanceBracket

Challenge 2

This Java program checks if a given string of brackets (parentheses, curly braces, and square brackets) is balanced or not. It defines a function called "isValid" that takes a string as input and returns a boolean value indicating whether the brackets are balanced or not. The program uses a stack data structure to keep track of the opening brackets and compare them with the closing brackets in the input string. If a closing bracket is found, the program checks whether it matches the most recent opening bracket on the stack. If not, the brackets are not balanced and the program returns false. If all brackets match and the stack is empty at the end of the iteration, the brackets are balanced and the program returns true.

To run the program, you can follow these steps:

  • Install Java on your computer if it's not already installed. You can download it from the official website: https://www.java.com/en/download/

  • Open a text editor and copy the code into a new file.

  • Save the file with a ".java" extension (e.g., BalanceBracket.java).

  • Open a terminal or command prompt and navigate to the directory where the file is saved.

  • Compile the code by running the command: javac BalanceBracket.java

  • Run the program by running the command: java BalanceBracket

  • The program will output the result of the "isValid" function for the default input ("{}"), which should be true. You can change the input by modifying the "x" variable in the "main" function.

balancebracket's People

Contributors

kavididesilva avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.