Big Java Late Objects
2nd Edition
ISBN: 9781119330455
Author: Horstmann
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 2, Problem 7RE
What are the values of the following expressions, assuming that n and m have type int, n is 17, and m is 18?
- a. n / 10 + n % 10
- b. n % 2 + m % 2
- c. (m + n) / 2
- d. (m + n) / 2.0
- e. (int) (0.5 * (m + n))
- f. (int) Math.round(0.5 * (m + n))
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
I did part A but I really need all parts of part B answered I want the code to continue after 0 with negative numbers and I need the guesses to show up at the end that shows how many guesses it took before the user ran out of points.
import java. util.Random;
import java.util. Scanner;
import java.util.regex.*;
public class HiLOGame{
public static void main( String(] args){
final int MAX POINT = 1000-
int point = MAX POINT:
int numberOfGuess = 0;
do {
numberOfGuess++:
showStatus(point);
int point ToRisk = getPointToRisk("Enter point to risk? ", point);
String option = getHiLoOption ("Enter either Hi or Lo?");
int magicNumber = getMagicNumber(1, 13);
/I for debug
//System.out.printf(String.format ("Magic number: %d%n",. magicNumber));
if (isWon(option, magicNumber)) {
point += pointToRisk:
System.out.printin("You Won this game.");
} else f
point -= pointToRisk:
System.out.printin("You Lost this game.");
}
}while (point > 0):
report(MAX POINT, numberOfGuess);
System.exit(0);
}…
Trace this C code:
What is the output of the following program segment? (Trace code and show your work)
int i = 1, j = 1, k = 5;
while (i+j < k)
{
printf("i = %d j = %d k = %d \n", i, j, k);
i = j + k;
j = i + k;
k = i + j;
}
printf("i = %d j = %d k = %d \n", i, j, k);
Correct any mistake(s) in the following Java code and write your answer on the right
(a) int x=1; y=2;
double z=2.0;
z=x;
(b) int x=1;
double y=2;
x=y;
(c) for (int i=10; i<=0; i++) {
System.out.print(“ i=”+i);
}
(d) for (int i=0; i<10; i--); {
System.out.print(“ i=”+i);
}
(e) int x = 18, y = 12;
x=x+2;
int y = 10;
x =x+y;
(f) int x = 18,
2=x+2;
(g) for ( i=0, i>5, i--)
System.out.println(“i= ”+i);
Chapter 2 Solutions
Big Java Late Objects
Ch. 2.1 - Declare a variable suitable for holding the number...Ch. 2.1 - What is wrong with the following variable...Ch. 2.1 - Declare and initialize two variables, unitPrice...Ch. 2.1 - Prob. 4SCCh. 2.1 - Some drinks are sold in four-packs instead of...Ch. 2.1 - Prob. 6SCCh. 2.1 - Prob. 7SCCh. 2.1 - Prob. 8SCCh. 2.1 - How would you explain assignment using the parking...Ch. 2.2 - A bank account earns interest once per year. In...
Ch. 2.2 - In Java, how do you compute the side length of a...Ch. 2.2 - The volume of a sphere is given by V=43r3 If the...Ch. 2.2 - Prob. 13SCCh. 2.2 - Prob. 14SCCh. 2.3 - Write statements to prompt for and read the users...Ch. 2.3 - What is wrong with the following statement...Ch. 2.3 - Prob. 17SCCh. 2.3 - What is problematic about the following statement...Ch. 2.3 - What is the output of the following statement...Ch. 2.3 - Using the printf method, print the values of the...Ch. 2.4 - Prob. 21SCCh. 2.4 - Suppose the architect specifies a pattern with...Ch. 2.4 - A robot needs to tile a floor with alternating...Ch. 2.4 - For a particular car, repair and maintenance costs...Ch. 2.4 - The shape of a bottle is approximated by two...Ch. 2.5 - What is the length of the string "Java Program"?Ch. 2.5 - Consider this string variable. String str = "Java...Ch. 2.5 - Use string concatenation to turn the string...Ch. 2.5 - Prob. 29SCCh. 2.5 - Prob. 30SCCh. 2 - Write declarations for storing the following...Ch. 2 - What is the value of mystery after this sequence...Ch. 2 - What is wrong with the following sequence of...Ch. 2 - Write the following mathematical expressions in...Ch. 2 - Write the following Java expressions in...Ch. 2 - What are the values of the following expressions?...Ch. 2 - What are the values of the following expressions,...Ch. 2 - What are the values of the following expressions?...Ch. 2 - Assuming that a and b are variables of type int,...Ch. 2 - Suppose direction is an integer angle between 0...Ch. 2 - Find at least five compile-time errors in the...Ch. 2 - Find three run-time errors in the following...Ch. 2 - Consider the following code segment. double...Ch. 2 - Explain the differences between 2, 2.0, 2, 2, and...Ch. 2 - Explain what each of the following program...Ch. 2 - Write pseudocode for a program that reads a word...Ch. 2 - Write pseudocode for a program that reads a name...Ch. 2 - Write pseudocode for a program that computes the...Ch. 2 - Modify the pseudocode for the program in How To...Ch. 2 - Prob. 20RECh. 2 - You are cutting off a piece of pie like this,...Ch. 2 - The following pseudocode describes how to obtain...Ch. 2 - Suppose you are given a string str and two...Ch. 2 - Prob. 24RECh. 2 - For each of the following computations in Java,...Ch. 2 - Prob. 26RECh. 2 - This chapter contains a number of recommendations...Ch. 2 - Write a program that displays the dimensions of a...Ch. 2 - Write a program that computes and displays the...Ch. 2 - Write a program that reads a number and displays...Ch. 2 - Write a program that prompts the user for two...Ch. 2 - Enhance the output of Exercise E2.4 so that the...Ch. 2 - Write a program that prompts the user for a...Ch. 2 - Write a program that prompts the user for a radius...Ch. 2 - Write a program that asks the user for the lengths...Ch. 2 - Improve the program discussed in How To 2.1 to...Ch. 2 - Write a program that helps a person decide whether...Ch. 2 - Write a program that asks the user to input The...Ch. 2 - File names and extensions. Write a program that...Ch. 2 - Write a program that reads a number between 1,000...Ch. 2 - Write a program that reads a number between 1,000...Ch. 2 - Printing a grid. Write a program that prints the...Ch. 2 - Write a program that reads in an integer and...Ch. 2 - Write a program that reads two times in military...Ch. 2 - Writing large letters. A large letter H can be...Ch. 2 - Write a program that transforms numbers 1, 2, 3, ,...Ch. 2 - Write a program that prints a Christmas tree:...Ch. 2 - Easter Sunday is the first Sunday after the first...Ch. 2 - In this project, you will perform calculations...Ch. 2 - The following pseudocode describes how a bookstore...Ch. 2 - The following pseudocode describes how to turn a...Ch. 2 - The following pseudocode describes how to extract...Ch. 2 - Giving change. Implement a program that directs a...Ch. 2 - An online bank wants you to create a program that...Ch. 2 - A video club wants to reward its best members with...Ch. 2 - Consider the following circuit. Write a program...Ch. 2 - The dew point temperature Td can be calculated...Ch. 2 - The pipe clip temperature sensors shown here are...Ch. 2 - Prob. 12PPCh. 2 - Consider the following tuning circuit connected to...Ch. 2 - According to the Coulomb force law, the electric...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
(Convert Celsius to Fahrenheit) Write a program that reads a Celsius degree in a double value from the console,...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Why might doctors and nutritionists be interested in a device like DietSensor?
Using MIS (10th Edition)
Which category of C++ reference variables always produces aliases?
Concepts Of Programming Languages
Write a program that prompts the user to input the name of a text file and then outputs the number of words in ...
Problem Solving with C++ (10th Edition)
Consider the adage Never ask a question for which you do not want the answer. a. Is following that adage ethica...
Experiencing MIS
Mass and Weight Scientists measure an objects mass in kilograms and its weight in newtons. If you know the amou...
Starting Out With Visual Basic (8th 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
- I need help in tracing the following program step by step. int foo1(int *A, int *B, int C) {int temp;temp = *A + C;*A = *B + C;*B = C + C;return temp;};int main(){int A = 1, B = 2, C = 3;C = foo1(&A, &B, C);B = foo1(&B, &C, A);A = foo1(&C, &A, B);printf("%d%d%d", A, B, C);return 0;}arrow_forwardWhat is the output of the following code?Assume that int is 32 bits, short is 16 bits, and the representation is two’scomplement. unsigned int x = 0xDEADBEEF;unsigned short y = 0xFFFF;signed int z =-1;if (x > (signed short) y) printf("Hello");if (x > z) printf("World"); (a) Prints nothing.(b) Prints ”Hello”(c) Prints ”World”(d) Prints ”HelloWorld”arrow_forwardTranslate the pseudocode in Section 2.4 for computing the number of tiles and the gap width into Java. number of pairs = integer part of (total width - tile width) / (2 x tile width)number of tiles = 1 + 2 x number of pairsgap at each end = (total width - number of tiles x tile width) / 2 I'm wondering why this test failed, during another test, it was good because the gap was 1.00. Is there something I should do in terms of rounding?arrow_forward
- Correct any mistake(s) in the following Java code(a). for (i=0, i<5, i++)System.out.println(“i= ”+i); Ans: (b). for (int j=0; i<5; i--) System.out.println(“j= ”+j); Ans: (c). for (int count=10, i>=0, count++)System.out.println(“count= ”+count); Ans: (d). for (int i=0; i<5; i++);System.out.println(“i= ”+i); Ans:arrow_forwardConsider the below method which computes the value x. Specifically, x = (a*b)/c, based on inputs a, b, and c. This function have several problems. public int computeX (int a, int b, int c){ int x = (a*b)/c; Rewrite the method to fix these errors. return x;}arrow_forwardI did part A but I really need all parts of part B answered I want the code to continue after 0 with negative numbers and I need the guesses to show up at the end that shows how many guesses it took before the user ran out of points and my code is messed up. import java.util.*;public class HiLo { public static void main(String[] args) { final int MAX_POINT = 1000; int point = MAX_POINT; int min = 1; int max = 13; int guess = 0; System.out.println("High Low Game."); System.out.println("RULES."); System.out.println("1. Numbers 1 through 6 are low ."); System.out.println("2. Numbers 8 through 13 are High ."); System.out.println("3. Numbers 7 is neither high or Low."); do { displayPoints(point); int pointToRisk = enterPointsToRisk(point); String option = predictHiLo("\nPredict <1=High, 0=Low>: "); int computerRandomNum = randomNumgen(min, max); if…arrow_forward
- Write a Java program based on the following situations. · Generate two random single-digit integers, (number1 and number2) · if both numbers are odd, then divide the max number by the min number. · if both numbers are even, then multiply two numbers. o If the result is 0 (zero), then print the your random numbers which is the 0. · If any of the numbers is even or odd, subtract the numbers (number1 – number2). o If the result is negative integer, then print “the result is negative”. o If the result is positive integer, then print “the result is positive”. o If the result is 0, then print “the result is 0”arrow_forwardWrite a program which reads the number of blocks the builders have,and outputs the height of the pyramids that can be built using these blocks.arrow_forwardWrite a program that reads a floating point number and prints "zero" if the number is zero. Otherwise, it prints "positive" or "negative" (as appropriate). Add "small" if the absolute value is less than 1, and add "large" if the absolute value is greater than 1000.arrow_forward
- What is the time complexity for the following code/program? for (int i = 1; i <= n; i++){ for (int j = 1; j <= 100; j++){ sum = i + j + k;}}arrow_forwardWrite a java program that will solve and display the problem below: Find three consecutive integers such that the sum of the first, twice the second, and three times the third is −76.arrow_forwardWrite Java program that print the following series of integers 1, 5, 9, 13, 17, 21, 25, . . . , 993, 997, 1001, . . . , 1997, 2001, 2005 and calculate the sum of the terms: (1 + 5 + 9 + 13 + . . . + 1997 + 2001 + 2005)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Introduction to Big O Notation and Time Complexity (Data Structures & Algorithms #7); Author: CS Dojo;https://www.youtube.com/watch?v=D6xkbGLQesk;License: Standard YouTube License, CC-BY