Concept explainers
Explanation of Solution
a.
Program:
//Import necessary header files
import java.util.*;
//Define the class
class Main
{
//Define the main() method
public static void main(String[] args)
{
//Initialize the variable x as 4
int x = 4;
//Check the condition
if (x > 5)
//True, Print A
System.out.println("A");
//Check the condition
else if (x < 10)
//True, Print B
System...
Explanation of Solution
b.
Program:
//Import necessary header files
import java.util.*;
//Define the class
class Main
{
//Define the main() method
public static void main(String[] args)
{
//Initialize the variable x as 5
int x = 5;
//Check the condition
if (x > 5)
//True, Print A
System.out.println("A");
//Check the condition
else if (x < 10)
//True, Print B
System...
Explanation of Solution
c.
Program:
//Import necessary header files
import java.util.*;
//Define the class
class Main
{
//Define the main() method
public static void main(String[] args)
{
//Initialize the variable x as 6
int x = 6;
//Check the condition
if (x > 5)
//True, Print A
System.out.println("A");
//Check the condition
else if (x < 10)
//True, Print B
System...
Explanation of Solution
d.
Program:
//Import necessary header files
import java.util.*;
//Define the class
class Main
{
//Define the main() method
public static void main(String[] args)
{
//Initialize the variable x as 9
int x = 9;
//Check the condition
if (x > 5)
//True, Print A
System.out.println("A");
//Check the condition
else if (x < 10)
//True, Print B
System...
Explanation of Solution
e.
Program:
//Import necessary header files
import java.util.*;
//Define the class
class Main
{
//Define the main() method
public static void main(String[] args)
{
//Initialize the variable x as 10
int x = 10;
//Check the condition
if (x > 5)
//True, Print A
System.out.println("A");
//Check the condition
else if (x < 10)
//True, Print B
System...
Explanation of Solution
f.
Program:
//Import necessary header files
import java.util.*;
//Define the class
class Main
{
//Define the main() method
public static void main(String[] args)
{
//Initialize the variable x as 11
int x = 11;
//Check the condition
if (x > 5)
//True, Print A
System.out.println("A");
//Check the condition
else if (x < 10)
//True, Print B
System...
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)
- The following is related to a Java Code: The following if statement determines whether choice is equal to ‘Y’ or ‘y’: if (choice == 'Y' || choice == 'y') Rewrite this statement so it makes only one comparison and does not use the || operator. 1) How will it get fixed?arrow_forwardWrite a program that determines an integer value the user had in mind. Your program first asks the user to enter the lower and upper bounds of the range that the integer belongs to, and then presents a series of questions “Is the number greater than x?” with yes/no answers to the user in order to determine the integer value that the user had in mind. For instance, if the integer in mind is 5 and the interaction between the user and your program is: Please enter the lower bound: -10 Please enter the upper bound: 50 Is the number greater than 20 (Y/N)? n Is the number greater than 4 (Y/N)? y Is the number greater than 12 (Y/N)? n Is the number greater than 8 (Y/N)? n Is the number greater than 6 (Y/N)? n Is the number greater than 5 (Y/N)? n Your program should then print: The number you had in mind is 5 Your program should ask roughly log2(upper_bound − lower_bound) questions. Your program A3_1.py should include a main() function and may include other functions that you prefer.…arrow_forwardWrite a program in java that determines the value, true or false, of the following logical expressions, assuming that the value of the (type int) variables cont is 10 and limite is 20 (cont == 0 ) && (limite < 20) (limite >= 20) || (cont < 5) ((limite/(cont-10)) > 7) || (limite <20) (limite <= 20) || ((limite/(cont-10)) > 7) ((limite/(cont-10)) > 7) && (limite < 0) (limite < 0) && ((limite/(cont-10))> 7)arrow_forward
- Write a program in Java to take an infix mathematical expression. The expression will contain single- or double-digit numbers, ‘+’, ‘-‘, ‘*’, and ‘/’ operators, and parenthesis. First check the validity of the expression with respect to the position of opening and closing parenthesis. If the expression is not valid then display appropriate message, otherwise, convert that infix expression to corresponding postfix expression, evaluate that postfix expression and print the final result. You can use relevant Java built-in classes in your code. The sample inputs/ outputs are given below: Sample inputs and outputs: (User’s inputs are shown in bold) Sample 1 Enter the mathematical expression: 15*(8–3*2)+16/4) The expression is invalid Sample 2 Enter the mathematical expression: 15*(8–3*2)+16/4 The postfix expression: 15 8 3 2 * - * 16 4 / + The final result: 34 Sometimes your deliver code is not showing. Please look up this issuesarrow_forwardWrite a program in Java to take an infix mathematical expression. The expression will contain single- or double-digit numbers, ‘+’, ‘-‘, ‘*’, and ‘/’ operators, and parenthesis. First check the validity of the expression with respect to the position of opening and closing parenthesis. If the expression is not valid then display appropriate message, otherwise, convert that infix expression to corresponding postfix expression, evaluate that postfix expression and print the final result. You can use relevant Java built-in classes in your code. The sample inputs/ outputs are given below: Sample inputs and outputs: (User’s inputs are shown in bold) Sample 1 Enter the mathematical expression: 15*(8–3*2)+16/4) The expression is invalid Sample 2 Enter the mathematical expression: 15*(8–3*2)+16/4 The postfix expression: 15 8 3 2 * - * 16 4 / + The final result: 34arrow_forwardWrite a C++ program that will allow the user to input the First Name, Last name, Middle Initial, and grade of a student. The following conditions must be observed: a. If the grade input is 96-100, the remark is “ you performed an excellent job! Keep it up !” b. If the grade input is 91-95, the remark is “ you performed a very satisfactory Job! Keep it up !” c. If the grade input is 86-90, the remark is “ you have satisfactory performance, you can improve some more. ” d. If the grade input is 80-85, the remark is “ your performance is fair, try harder” e. If the grade input is 75-79, the remark is “ your performance needs Improvement, you can do it” f. If the grade input is below 75, the remark is “ we’re sorry but you failed, we know you can do better next time” Test your program using the following TEST CASES: CASE 1: Input first name: Juan Input last name: Cruz Input middle Initial:…arrow_forward
- Write a C++ program that will allow the user to input the First Name, Last name, Middle Initial, and grade of a student. The following conditions must be observed: a. If the grade input is 96-100, the remark is “ you performed an excellent job! Keep it up !” b. If the grade input is 91-95, the remark is “ you performed a very satisfactory Job! Keep it up !” c. If the grade input is 86-90, the remark is “ you have satisfactory performance, you can improve some more. ” d. If the grade input is 80-85, the remark is “ your performance is fair, try harder” e. If the grade input is 75-79, the remark is “ your performance needs Improvement, you can do it” f. If the grade input is below 75, the remark is “ we’re sorry but you failed, we know you can do better next time”arrow_forwardI have to display the number of available burgers and customers waiting in my program. If the producer cooks a burger, it adds up to the available burgers and whenever a customer buys a burger, the number of the available burgers is reduced. And when there are 0 burgers available left and a customer buys a burger, it is added up to the customer waiting. Then if the producer cooks a burger, the available burgers will remain the same but the customer waiting is decreased. The code is given below and I am stuck at display the correct output. What should be done?arrow_forwardWrite a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and E, possibly followed by + or -. Their numeric values are 4, 3, 2, 1, and 0. There is no F+ or F-. A + increases the numeric value by O.3, a – decreases it by 0.3. However, an A+ has value 4.0. Enter a letter grade: B- The numeric value is 2.7.arrow_forward
- In C++ Programming. Solve the following problem statements by simulating the given values of the variables below. int X = 5, Y = 10, Z = 15; int A = 2, B = 4, C = 6; 1. If X = Y; X = Z what is the value of X? 2. If B = C; A = X; Y = Z what is the value of A? 3. If A = B; B = C; C = X what is the value of A? 4. If Z = Y; Y = X; Y = Z what is the value of Z? 5. If X = B; X = C; what is the value of X?arrow_forwardConsider the following program:int x = 1, y = 1; co <x=x+y;>|| y=0; ||x=x-y; oc(a) Does the program meet the requirements of the At-Most-Once Property (2.2)? Explain.(b) What are the final values of × and y? Explain your answer.arrow_forwardTrace of the following Java code and show what is printed (the values of the variable 'c' ) int a = 2, b = 10, c = 3; while ( b > 0 && a <= 7 ) { b = b - 2; c = c + a; System.out.print ( c + “ , “ ); if ( c < b ) b ++; else c ++; a = a + 2; } a. 5 9 12 15 b. 5 8 15 c. 5 9 16 d. 5 8 16 18arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education