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
prisoha [69]
3 years ago
10

Java !!!

Computers and Technology
1 answer:
coldgirl [10]3 years ago
7 0

Answer:

Explanation:

import java.util.*;

public class BalancedBrackets {

// function to check if brackets are balanced

static boolean isBalanced(String expr)

{

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

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

{

char x = expr.charAt(i);

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

{

// Push the element in the stack

stack.push(x);

continue;

}

if (stack.isEmpty())

return false;

char check;

switch (x) {

case ')':

check = stack.pop();

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

return false;

break;

case '}':

check = stack.pop();

if (check == '(' || check == '[')

return false;

break;

case ']':

check = stack.pop();

if (check == '(' || check == '{')

return false;

break;

}

}

// Check Empty Stack

return (stack.isEmpty());

}

public static void main(String[] args)

{

Scanner scan = new Scanner(System.in);

System.out.println("\nEnter the expression to check is balanced or not !");

String expr = scan.nextLine();

boolean output;

output = isBalanced(expr);

System.out.println(output);

if (output)

System.out.println("Balanced ");

else

System.out.println("Not Balanced ");

scan.close();

}

}

You might be interested in
Arpenet was the computer created by the military true or false
Sphinxa [80]

True. It was a project that the pentagon was working on in the 60's

3 0
3 years ago
Complete the sentences about interactive media.
maksim [4K]

Answer:

teletext

dynamic media

Explanation:

5 0
3 years ago
In order to avoid slipping in the shop, your footwear should ___________.
Arisa [49]

Answer:

b

Explanation:

has traction so it can grip

4 0
3 years ago
Which of the following are wise entrepreneurial decisions or concepts? Check all of the boxes that apply.
Artyom0805 [142]

Answer:

a b e d f

Explanation:

8 0
3 years ago
Read 2 more answers
A cast is required in which of the following situations? a. using charAt to take an element of a String and store it in a char b
notka56 [123]

Answer:

Option(d) i.e "storing a float in an int" is the correct answer for the given question.

Explanation:

  • Typecast is used for the changing the one datatype to the another datatype Their are two types of casting  

1 implicit

In this typecast we change the smaller datatype into the larger datatype.

For example

int to float  

2 Explicit  

In this typecast we change the larger datatype into the smaller datatype in an explicit manner.

For example

float to int.

  • in the given question we required the casting in the option(d) i.e "storing float in an int" That's why this option is correct and all other options are incorrect.
3 0
4 years ago
Other questions:
  • Omar’s teacher has asked him to send her a PDF copy of his presentation via email.
    11·1 answer
  • Software that helps you navigate the web is called
    9·1 answer
  • When preparing to communicate a solution to a design problem, you must:?
    5·1 answer
  • Respond to the following in three to five sentences. Select the workplace skill, habit, or attitude described in this chapter th
    15·2 answers
  • Which is the fastest CPU and why?
    5·1 answer
  • When the computer is turned on, the operating system is loaded from the hard disk to the _________________. *​
    10·1 answer
  • Complete the sentence.
    10·1 answer
  • 1. Give one reason why data is represented in binary in a computer [1]
    10·1 answer
  • Describe the difference between information poor and information rich society?​
    12·2 answers
  • To set up scenarios,then set up a list, then set up the reference cell. to set up the cells that display the output results from
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!