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
Rom4ik [11]
3 years ago
15

Write a function int checkBalance(char exp[]); that can take an expression as input and check whether the parenthesis used in th

at expression are valid or invalid. It returns 1 if it is valid, and returns 0 if it is not valid.For example, the following expressions are valid: [ A * {B (C D)}] and [{()()}]The following expressions are invalid: [ A * {B (C D})], [ { ( ] ) ( ) }
Computers and Technology
1 answer:
mylen [45]3 years ago
3 0

Answer:

Explanation:

The following code is written in Java. It uses for loops to loop through the array of characters, and uses IF statements to check if the symbols in the expression are balanced. If so it returns true, otherwise it breaks the function and returns false. Two test cases have been provided in the main method and the output can be seen in the attached image below.

import java.util.ArrayList;

class Brainly {

   public static void main(String[] args) {

       char[] exp = { '[', 'A', '*', '{', 'B', '(', 'C', 'D', ')', '}', ']'};

       char[] exp2 = {'[', 'A', '*', '(', 'C', '}', ']'};

       System.out.println(checkBalance(exp));

       System.out.println(checkBalance(exp2));

   }

   public static boolean checkBalance(char exp[]) {

       ArrayList<Character> symbols = new ArrayList<>();

       for (char x: exp) {

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

               symbols.add(x);

           }

           if (x ==']') {

               if (symbols.get(symbols.size()-1) == '[') {

                   symbols.remove(symbols.size()-1);

               } else {

                   return false;

               }

           }

           if (x =='}') {

               if (symbols.get(symbols.size()-1) == '{') {

                   symbols.remove(symbols.size()-1);

               } else {

                   return false;

               }

           }

           if (x ==')') {

               if (symbols.get(symbols.size()-1) == '(') {

                   symbols.remove(symbols.size()-1);

               } else {

                   return false;

               }

           }

       }

       return true;

   }

}

You might be interested in
Which of the following statements are true about file naming conventions? Check all of the boxes that apply.
Korolek [52]

Answer:

last one check it and the second one

Explanation:

8 0
3 years ago
Read 2 more answers
Any fact or set of facts, such as the words in a letter to a friend or the notes in a song, can become computer ____.
Alina [70]

I think the answer is... data

3 0
3 years ago
Banks use _____, which are electronic transmissions of account exchange information over private communications’ networks.
faltersainse [42]

Answer:

Wire transfer

Explanation:

Wire Transfer also known as remittance under the U.S. law is the electronic transfer of money which is carried out across a network that is run by several banks and money transfer agencies around the globe. With Wire Transfer, people at different parts of the Word can securely send money to individuals at other financial institution in any part of the world.

The following are important points to note about wire transfers:

1. It is an electronic transfer of funds across a network of banks and money transfer agencies around the world.

2. The individual or senders pays a transaction fee at their banks and must provide the receivers details including bank name and account number.

3. Wire transfers can take up to two working days to complete

4. The Office of Foreign Assets monitors and controls international wire payments, to prevent money laudering and funding of illegal activities like terrorism

7 0
2 years ago
Alt +f4 is a short cut of close a document in MS word /ture /false​
vesna_86 [32]

Answer:

True.

Explanation:

Microsoft Word refers to a word processing software application or program developed by Microsoft Inc. to enable its users to type, format and save text-based documents.

In Computer science, there are specific key combinations (short cut) that avail end users the opportunity to perform specific functions without having to go through a series of step.

For example, when you press the Alt button and function key 4 (F4) at the same time, it would close the current open window.

Hence, Alt + F4 is a short cut key that can be used to close a document in MS word.

8 0
2 years ago
Answer quickly!!!
ioda

Answer: Harry should check that font he has used are readable on every page and element of his website


Harry should check that all images have alt texts

Explanation: edmentum

7 0
1 year ago
Other questions:
  • HELP NOW PLZZ/ Question: Complete the sentence with the correct response.
    11·1 answer
  • Why does people that gets abused not report?
    5·1 answer
  • • Write a program to find the maximum, minimum, and average score of players. The input to the program is a file containing play
    9·1 answer
  • What are some characteristics of filtering junk email in Outlook 2016? Check all that apply.
    9·2 answers
  • What is the square root of 1600 and 36 ?​
    6·1 answer
  • when using presentation software, which menu can you use to duplicate a slide to use as a template for a new slide?
    14·1 answer
  • Write a Python3 program to check if 3 user entered points on the coordinate plane creates a triangle or not. Your program needs
    12·1 answer
  • Write a small program that takes in two numbers from the user. Using an if statement and an else statement, compare them and tel
    12·1 answer
  • 1. What are you going to do if someone ask for your personal information online?​
    12·2 answers
  • If C2=20 and D2=10 what is the result of the function = mathcal I F(C2=D2,^ prime prime Ful "Open")?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!