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]
3 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]3 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
Antivirus software products require that you update _____ on a regular basis
german
Operating System, as far as I know @[email protected]
5 0
3 years ago
Read 2 more answers
Is mayonnaise technically an instrument?
stich3 [128]
No it doesn’t count as an instrument
7 0
3 years ago
Which of the following tools enables users to connect to a remote computer, including servers with no interaction required from
lana66690 [7]

Answer:

Remote Desktop

Explanation:

This is a software, that enable you to connect with a remote computer with all access. e.g. Team Viewer

3 0
3 years ago
Why did it take hundreds
levacccp [35]
Before that there was no way for the image to be recorded and fixed on a surface
5 0
2 years ago
Most printers are plug and play compatible and must be manually configured when they are plugged into the system.
nikdorinn [45]

Answer:

False

Explanation:

Plug and play devices are computer peripheral devices that can be used immediately, with little or no necessary configuration when plugged or connected to the computer system.

Printers are mostly electronic devices used as an output of a hard copy of a computer system application document. They are not part of the computer system (peripheral devices). They come with installation disk which a computer must install, in order to be able to use the printer.

Yes they are peripheral devices, but they are not plug and play devices since its software must be installed on the computer, to use it

8 0
3 years ago
Read 2 more answers
Other questions:
  • Where is the error in this code sequence?
    11·1 answer
  • What are some measurements used to determine water waste from leaking faucets?
    10·1 answer
  • Sara has a habit of stealing money from her brother Charlie. When he found out, Charlie rebuked Sara in the presence of his frie
    11·1 answer
  • In evaluating the precedence rules used by Python, what statement is accurate? a. Addition and subtraction are evaluated after a
    8·2 answers
  • Which type of drawer has three dispensing modes: single-dose, multi-dose, and matrix?
    13·1 answer
  • A _____ is a climate-controlled building or set of buildings that houses database servers and the systems that deliver mission-c
    6·1 answer
  • If Asa changes the text to bold, he has changed the style. True False
    8·2 answers
  • What is my favorite color?<br> Red<br>Orange<br>Yellow<br>Blue <br>Gold<br>Silver
    13·1 answer
  • Gimme Shelter Roofers maintains a file of past customers, including a customer number, name, address, date of job, and price of
    8·1 answer
  • What is the difference between referential and entity integrity
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!