Answer:
Code is completed below
Explanation:
Source Code in Java:
class Parenthesis
{
boolean hasBalancedParentheses(String eq) //method to check and return if a set of parenthesis is balanced or not
{
int count=0; //to store count of current unclosed opening brackets
for(int i=0;i<eq.length();i++)
{
if(eq.charAt(i)=='(')
count++;
else if(eq.charAt(i)==')')
count--;
if(count<0) //if count falls below zero, there were more closing brackets than opening brackets till this point
return false;
}
if(count>0) //if count is still more than zero, there were less closing brackets than opening brackets
return false;
return true; //if program reaches this point, it has passed all the tests
}
public static void main(String args[])
{
//testing the function
Parenthesis ob=new Parenthesis();
System.out.println(ob.hasBalancedParentheses("()(()())((())())"));
System.out.println(ob.hasBalancedParentheses(")((()())(()))())"));
}
}
Rapid prototyping as it allows the production of a functional program in a short time
Answer:
Statement:
print("first is "+str(first)+" second = "+str(second)) # It is a python statement where first and second are variable of any type.
Explanation:
- The above statement is the print statement that prints the value of first and second variables like in the form of "first is" value of the first variable, then space, then "second = b" and then the value of the second variable.
- The value for the first and the second variable of any type but it convert it into string form with the help of str() function in the print statement.
- The string of the print statement can be formed by the help '+' operator which adds the string with the value and the other string in print statement in java and python language.
Answer:
The advantages and disadvantages of the given instance are described below.
Explanation:
<u>Advantage</u>:
- Cost reductions are the greatest advantages of cloud computing. It lets users conserve considerable capital costs and they wouldn't need any actual hardware expenditure.
<u>Disadvantage</u>:
- If you operate in something like a cloud system, your program is operating on a platform that offers services to these other organizations at around the same time.
name = input("What's your name? ")
print("Hello " + name + ", welcome to my quiz!")
score = 0
di = {"qustion1": "answer1", "qustion2": "answer2", "qustion3": "answer3", "qustion4": "answer4", "qustion5": "answer5", "qustion6": "answer6",
"qustion7": "answer7", "qustion8": "answer8", "qustion9": "answer9", "qustion10": "answer10"}
for x in di:
user_answer = input(x+" ")
if user_answer == di[x]:
print("That's correct!")
score += 1
else:
print("The correct answer is " + str(di[x]))
print("You got "+str(score)+" out of 10!")
I iterated through a dictionary with the questions and answers as the keys and values respectively. I hope this helps!