1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
wolverine [178]
4 years ago
13

Programming challenge description: Given a string comprising just of the characters (,),{,},[,] determine if it is well-formed o

r not. Input: Your program should read lines from standard input. Each line contains a string comprising of the characters mentioned above. There is no whitespace between characters. Output: Print out True if the string is well-formed, False otherwise.
Computers and Technology
1 answer:
nadezda [96]4 years ago
5 0

Answer:

Employing Java language,

Explanation:

//for using stack data structure

import java.util.Stack;

//class definition

public class BracketMatch {

   //function to find the string is well formed or not

   public static boolean isWellFormed(String str) {

       //variable to store the character value

       char ch;

       //check if the first character itself is the end of the brackets

       if (str.charAt(0) == ')'||str.charAt(0) =='}'||str.charAt(0) ==']')

           return false;

       //creating a stack of character type

       Stack<Character> stack = new Stack<Character>();

       //iterating through the characters in string

       for(int i=0; i < str.length(); i++) {

           //storing the current character from the string in the variable

           ch = str.charAt(i);

           if(ch == '('||ch=='{'||ch=='[')

               //if the character is starting of the brackets push it into stack

               stack.push(ch);

           else if(ch == ')')

               //if it is closing bracket and the stack is empty then the string is not well formatted

               if(stack.empty())

                   return false;

               else if(stack.peek() == '(')

                   stack.pop();

               else

                   return false;

           else if(ch == '}')

               if(stack.empty())

                   return false;

               else if(stack.peek() == '{')

                   stack.pop();

               else

                   return false;

       }

       //returning the stack content, if the string will be well formed the stack would be empty

       //after all the operations

       return stack.empty();

   }

   //main method

   public static void main(String[] args) {

       //calling function to find if the string is welll formatted or not

       System.out.println(isWellFormed("{}"));

       //calling function to find if the string is welll formatted or not

       System.out.println(isWellFormed("([)]"));

   }

}

You might be interested in
What is a histogram?
Mice21 [21]

Answer:

I’m pretty sure its C. Can you mark me Brainliest if I am correct? Thank you have a nice day!

Explanation:

8 0
4 years ago
Which is a safe practice when online
Kay [80]

Answer:

I don't know if there are choices but these are couple that i think would be right. Don't give out personal info, have a complex password and don't give it out to anyone, don't click on random pop up adds, and use a firewall

Explanation:

7 0
3 years ago
Read 2 more answers
Which of the following scenarios can best be addressed by operations management?
Alborosie

Answer:

We need to shorten the time it takes to pick a customer order.

Explanation:

The operations management is the department in charge of supervising the operations related to the production and delivery of a product or a service of a company to its customers.

It would then them who would be in charge of reviewing the process or steps it takes to pick a customer order.

The other options are issues for the human resources department.

7 0
3 years ago
3.1.14 Wormhole CodeHS <br><br> May I have it in a copy and paste, please?
Sauron [17]

Answer:

3.1.14 Wormhole CodeHS

Explanation:

3.1.14 Wormhole CodeHS

6 0
3 years ago
Which ipv4 ip class provides for 126 unique networks, each having up to 16,777,214 hosts?
Sliva [168]
Class A.






----------------------------------------
3 0
3 years ago
Other questions:
  • Question 16 (2 points) Question 16 Unsaved
    11·1 answer
  • In computer security, the term "Dumpster diving" is used to describe a practice of sifting through trash for discarded documents
    7·1 answer
  • Which statement correctly explains why televisions became less bulky?
    6·1 answer
  • An engineer's desktop PC connects to a switch at the main site. A router at the main site connects to each branch office through
    5·1 answer
  • An adjustable wrench's movable jaw is positioned <br> by​
    5·1 answer
  • A student builds a model of an ATP molecule out of some scraps she finds at home. She uses a block of wood for the bulk of the m
    5·1 answer
  • What is a compiler? O a tool used to integrate multiple software programs O a tool used to extract a single software program fro
    13·2 answers
  • Uuhdcnkhbbbbhbnbbbbnnnnnnnnnfddjkjfs
    14·1 answer
  • Which line of code will cause the loop to execute exactly one time?
    13·1 answer
  • The ability to understand a person's needs or intentions in the workplace is demonstrating
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!