Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 3.2, Problem 14STQ
What output is produced by the following statements?
System.out.println(true &&false);
System.out.println(true | | false);
System.out.println(false && (x > 0));
System.out.println(true | | (x > 0));
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The following statements are
intended to alert a user to
dangerously high oral thermometer
readings (values are in degrees
Fahrenheit). Are they correct or
incorrect? If they are incorrect,
explain why and correct them.
if temp 97.5
disp ('Temperature normal');
elseif temp 99.5
disp ('Temperature slightly high');
elseif temp 103.0
disp ('Temperature dangerously high');
end
matlab
Examine the following for loop and
determine how many times this
loop will be executed.
for kk
[O 5 ; 3 3]
%3D
O 4
5
2
Given the following program and test cases:mid() { (5,3,2) (4 3 7) (4 7 3)int x,y,z,m;1: read("Enter 3 numbers:",x,y,z); X X X2: m = z; X X X3: if (y<z) X X X4: if (x<y) X5: m = y;6: else if (x<z) X7: m = y; // bug X8: else X X9: if (x>y) X X10: m = y; X11: else if (x>z) X12: m = x; X13: print("Middle number is:", m); X X X} Pass Fail PassWhich is(are) the row(s) with higher suspiciousness using Tarantula formulaQuestion 2 options:44,74,6,77
===========================================================================
Given the following program and test cases:mid() { (5,3,2) (4 3 7) (4 7 3)int x,y,z,m;1: read("Enter 3 numbers:",x,y,z); X X X2: m = z; X X X3: if (y<z) X X X4: if (x<y) X5: m = y;6: else if (x<z) X7: m = y; // bug X8: else X X9: if (x>y) X X10: m = y; X11: else if (x>z) X12: m = x; X13: print("Middle number is:", m); X X X} Pass Fail Pass
A. Trace the following pieces of code and give their exact output.
i.
int p
27;
switch (--p) {
case 28: System.out.println ("bbbb"); break;
case 27: System.out.println("abab"); break;
case 26: System.out.println ("aaaa");
default: System.out.println("@@ @ @ " ) ;
}
System.out.println(" After switch: P =
" + p);
ii.
int a = 100, b
17;
System.out.println (a%b);
System.out.println(a/b);
System.out.printf("%.3f\n",(double)a/b);
Chapter 3 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 3.1 - Suppose goals is a variable of type int. Write an...Ch. 3.1 - Suppose goals and errors are variables of type...Ch. 3.1 - Suppose salary and deductions are variables of...Ch. 3.1 - Suppose speed and visibility are variables of type...Ch. 3.1 - Suppose salary and bonus are variables of type...Ch. 3.1 - Assume that nextWord is a string variable that has...Ch. 3.1 - Prob. 7STQCh. 3.1 - What output is produced by the following code? int...Ch. 3.1 - Suppose you change the code in the previous...Ch. 3.1 - What output is produced by the following code? int...
Ch. 3.2 - Suppose number is a variable of type int that has...Ch. 3.2 - What output is produced by the following...Ch. 3.2 - What output is produced by the following...Ch. 3.2 - What output is produced by the following...Ch. 3.3 - What output is produced by the following code?Ch. 3.3 - Suppose you change the code in the previous...Ch. 3.3 - What output is produced by the following code?Ch. 3.3 - What output is produced by the following code?Ch. 3.3 - Suppose you change the first line of the code in...Ch. 3.3 - Prob. 20STQCh. 3.4 - Suppose you change the order of the drawing...Ch. 3.4 - Prob. 22STQCh. 3.4 - Write code for a JOptionPane dialog that will ask...Ch. 3 - Write a fragment of code that will test whether an...Ch. 3 - Write a fragment of code that will change the...Ch. 3 - Suppose you are writing a program that asks the...Ch. 3 - Prob. 4ECh. 3 - Consider the following fragment of code: What is...Ch. 3 - We would like to assess a service charge for...Ch. 3 - What is the value of each of the following boolean...Ch. 3 - The following code fragment will not compile. Why?...Ch. 3 - Prob. 9ECh. 3 - Consider the boolean expression (2 5) (x 100))....Ch. 3 - Write a switch statement to convert a letter grade...Ch. 3 - Consider the previous question, but include + or ...Ch. 3 - Imagine a program that displays a menu of five...Ch. 3 - Repeat the previous exercise, but define an...Ch. 3 - Repeat Exercise 13, but use a multibranch if-else...Ch. 3 - Given that the int variable temp contains a...Ch. 3 - Write Java statements that create a yes-or-no...Ch. 3 - A number x is divisible by y if the remainder...Ch. 3 - Write a program to read in three nonnegative...Ch. 3 - Write a program that reads three strings from the...Ch. 3 - Write a program that reads a one-line sentence as...Ch. 3 - Write a program that allows the user to convert a...Ch. 3 - Write a program that inputs an integer. If the...Ch. 3 - Prob. 7PCh. 3 - Repeat Programming Project 5 of Chapter 2, but...Ch. 3 - Repeat any of the previous Practice Programs using...Ch. 3 - Suppose that we are working for an online service...Ch. 3 - Write a program that reads a string from the...Ch. 3 - Repeat the calorie-counting program described in...Ch. 3 - Repeat Programming Project 5 but in addition ask...Ch. 3 - Repeat Programming Project 11 in Chapter 2, but if...Ch. 3 - Write a program to play the rock-paper-scissor...Ch. 3 - Prob. 9PPCh. 3 - Repeat Programming Project 8 in Chapter 1, but add...Ch. 3 - Write a program that inputs two strings that...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
Describe two properties that each candidate key must satisfy.
Modern Database Management (12th Edition)
Identity the termination condition in each of the following iterative statements. a. while (Count 5): . . . b....
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
What does the term multitasking mean?
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
(Greatest Common Divisor) The greatest common divisor (GCD) of two integers is the largest integer that evenly ...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Find the errors in the following code: 2. // Warning! This code contains an ERROR! if (average = 100) System.ou...
Starting Out with Java: Early Objects (6th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- What will be the final value of the variable x after execution of the given statement. Initial value of x is 3. x = ++x + ++xarrow_forwardWrite declarations to declare each variable to have the specified type and initial value: Problem: numberOfDeposits and numberOfChecks to be of type int, each with an initial value of 0; totalDeposits and totalChecks to be of type double, each with an initial value of 0.0; and serviceCharge to be of type double with an initial value of 0.25arrow_forwardAnalyze the following code: Code 1: int number = 45;boolean even; if (number % 2 == 0) even = true;else even = false; Code 2:int number = 45;boolean even = (number % 2 == 0); a. Code 1 has compile errors.b. Code 2 has compile errors.c. Both Code 1 and Code 2 have compile errors.d. Both Code 1 and Code 2 are correct, but Code 2 is better. What is the output from System.out.println((int)Math.random() * 4)?a. 0b. 1c. 2d. 3e. 4 Given |x - 2| <= 4, which of the following is true?a. x - 2 <= 4 && x - 2 >= 4b. x - 2 <= 4 && x - 2 > -4c. x - 2 <= 4 && x - 2 >= -4d. x - 2 <= 4 || x - 2 >= -4 Given |x - 2| >= 4, which of the following is true?a. x - 2 >= 4 && x - 2 <= -4b. x - 2 >= 4 || x - 2 <= -4c. x - 2 >= 4 && x - 2 < -4d. x - 2 >= 4 || x - 2 < -4 What is the output of the following code? boolean even = false;System.out.println((even ? "true" : "false")); a. trueb. falsec. nothingd. true falsearrow_forward
- Show the output of the following code: Explain brieflyint a = 6;int b = a++;System.out.println(a);System.out.println(b);a = 6;b = ++a;System.out.println(a);System.out.println(b);arrow_forwardWrite a program named InputMethodDemo2 that eliminates the repetitive code in the InputMethod() in the InputMethodDemo program in Figure 8-5. Rewrite the program so the InputMethod() contains only two statements: one = DataEntry("first");two = DataEntry("second"); (Note: The program in Figure 8-5 is provided as starter code.) Figure 8-5:arrow_forwardWrite a JAVA program that determines the alert level for the COVID-19 based on the percentage of new cases out of PCR tests carried out as indicated in the following table: Percentage of New Cases < 3% Between 3% and 6% (inclusive) Between 6% and 9% (exclusive) 9% or above Alert Level Green Yellow Orange Red % of new cases = (number of new cases / number of PCR tests) x 100 The program should ask the user to input the number of new cases and the number of PCR tests that were carried out. The program should display the percentage of new cases and the alert level. Sample Input / Output Input the number of new cases and number of PCR tests: 280 12000 % of new cases is 2.333333333333335% The Current Alert Level is Yellow Note: Your answer should follow the given sample input / output.arrow_forward
- What is the major advantage of using a for loop instead of a while loop? a. Unlike with a while loop, the execution of multiple statements can depend on the test condition. b. With a for loop, it is impossible to create an infinite loop. c. It is the only way to achieve an indefinite loop. d. The loop control variable is initialized, tested, and altered all in one place.arrow_forwardWhat is the output of the statements below? x=3 while xarrow_forwardWrite a JAVA program that determines the alert level for the COVID-19 based on the percentage of new cases out of PCR tests carried out as indicated in the following table: Percentage of New Cases < 2% Between 2% and 5% (inclusive) Between 5% and 8% (exclusive) 8% or above Alert Level Green Yellow Orange Red % of new cases = (number of new cases / number of PCR tests) x 100 The program should ask the user to input the number of new cases and the number of PCR tests that were carried out. The program should display the percentage of new cases and the alert level. Sample Input / Output Enter the number of new cases: 280 Enter the number of PCR tests: 12000 Percentage of new cases is 2.333333333333335% Alert Level is Yellow Note: Your answer should follow the given sample input / output.arrow_forward
- Write a program that prompts the user to input five decimal numbers. The program should then add thefive decimal numbers, convert the sum to the nearest integer, and print the result. Use the static_caststatement with an appropriate equation to convert the sum to an integer. Compile and run yourprogram with the following test data:Case 1: Input: 5.1, 5.1, 5.1, 5.1, 5.1. Expected Output: 26.Case 2: Input: 5.0, 5.0, 5.0, 5.0, 5.0. Expected Output: 25. The language is C++arrow_forwardwhat is the output of the following statements int x = 1;System.out.println(++x); 0 1 No output because there is a run time error 2arrow_forwardWrite the lines(s) of code required to instantiate a patient object called sick and set that patient's heart rate to 75. You may choose the values of other parameters for this patient, but only use methods/constructors that have been provided (or that you wrote) on the the previous page).arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Constants, Variables, Data types, Keywords in C Programming Language Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=d7tdL-ZEWdE;License: Standard YouTube License, CC-BY