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
Plzz help will mark brainliest
vlabodo [156]

Answer:

11. 3 dimensions

12. ( i believe its number 3)

13. 2 option

14. Natural Light

15. Development

Explanation:

7 0
3 years ago
The tcp protocol provides error detection and correction. <br><br> a. True <br> b. False
ANEK [815]
B. False

Explanation

TCP provides reliable, ordered, and error-checked delivery of a stream of octets (bytes) between applications running on hosts communicating via an IP network.
4 0
1 year ago
Now, we’re ready to program! Leave the visualizer and go back to https://repl.it/ to write your program. Here is the pseudocode
svlad2 [7]

Answer:

here

Explanation:

6 0
2 years ago
"The reason the virus exists is population control. They did this in a lab on purpose!"
Shkiper50 [21]
The correct answer is C
7 0
3 years ago
What is entered into a cell that is typically numeric and can be used for calculations? A. Value B. Function C. Label D. Tab
Greeley [361]
The answer can not be a label because it goes above the chart, and a tab doesn't have to do with a cell and a function is done without the cell so the answer is A. Value
3 0
3 years ago
Read 2 more answers
Other questions:
  • Create a stored procedure named prc_inv_amounts to update the INV_SUBTOTAL, INV_TAX, and INV_TOTAL. The procedure takes the invo
    8·1 answer
  • When you use the ip address of the web server, the correct site is displayed?
    15·1 answer
  • Which button, when pressed, allows light from the subject to fall on the sensor?
    8·1 answer
  • If the base-10 system stops with the<br> number 9, then why isn't it called<br> base-9?
    15·1 answer
  • In Microsoft Word you can access the _______ command from the "Mini toolbar." 
    9·1 answer
  • Which of the following is NOT one of the three basic structures used to solved logical problems?
    7·1 answer
  • Meaning of ‘integrity of data’
    14·2 answers
  • Please help I will mark brainliest ⚡️⚡️⚡️⚡️
    12·1 answer
  • Messages that have been accessed or viewed in the Reading pane are automatically marked in Outlook and the message subject is no
    10·2 answers
  • If Anime Characters were real , Who Would Your Anime Wife Would Be (Tell Who And Why)
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!