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
Textbook Question
Chapter 2, Problem 6E
If the int variable x contains 10, what will the following Java statements display?
system.out.println(“Test 1” + x * 3 * 2.0);
System.out.println(“Test 2” + x * 3 + 2.0);
Given these results, explain why the following Java statement will not compile:
System.out.println(“Test 3” + x * 3 − 2.0);
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Please explain the questions below.
//8. Experiment with the below code. When would you use this data type?
// In Java "or" is represented by || and "and" is represented as &&
//boolean x = 0;
//boolean x = true;
//x = !x;
//x = x || false;
//System.out.println(x);
//9. Explain what's going on here.
//char x = 'A';
//char x = 65;
//char x = 'A'; x++;
//char x = 12;
//System.out.println("x = " + x);
Write a java program called Sales considering the following directions and the sample run. Practice here first the write answer on the answer sheet. Also, make sure to distinguish high and low caps as Java is case - sensitive.
- import and declare a Scanner class
- declare three floating – point variables named price, discount, and discountPrice
- ask the user for the price (print statement) and get the price (Scanner) from the user
- calculate the discount if price is less than 100, then the discount is 10% of price, else discount is 14% of price
- print the discounted prices for the item
Sample Run
Enter the price
90.0
The discount price is 81.0
Enter the price
200.0
The discount price is 172.0
What will this Java statement print? Will it give error?
System.out.println(1.0 / 0);
Chapter 2 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 2.1 - Prob. 1STQCh. 2.1 - Can a Java program have two different variables...Ch. 2.1 - Prob. 3STQCh. 2.1 - Give the declaration for two variables of type...Ch. 2.1 - Write the declaration for two variables called...Ch. 2.1 - What is the normal spelling convention for named...Ch. 2.1 - Prob. 7STQCh. 2.1 - Prob. 8STQCh. 2.1 - Prob. 9STQCh. 2.1 - Prob. 10STQ
Ch. 2.1 - Prob. 11STQCh. 2.1 - In the Programming Tip entitled Type Casting a...Ch. 2.1 - What is the output produced by the following lines...Ch. 2.1 - What is the output produced by the following lines...Ch. 2.1 - Prob. 15STQCh. 2.1 - Prob. 16STQCh. 2.1 - Consider the following statement from the program...Ch. 2.1 - Prob. 18STQCh. 2.2 - Prob. 19STQCh. 2.2 - What output is produced by the following...Ch. 2.2 - What output is produced by the following...Ch. 2.2 - What output is produced by the following...Ch. 2.2 - What output is produced by the following...Ch. 2.2 - What output is produced by the following...Ch. 2.2 - What is the value of the expression sl.equals(s2)...Ch. 2.2 - What is the value of the expression s1.equals (s2)...Ch. 2.3 - Write Java statements that will cause the...Ch. 2.3 - What is the difference between the methods...Ch. 2.3 - Write a complete Java program that reads a line of...Ch. 2.3 - Write a complete Java program that reads one line...Ch. 2.3 - What output is produced by the following...Ch. 2.4 - Prob. 32STQCh. 2.4 - What is the output produced by the following Java...Ch. 2.4 - Although it is kind of silly, state legislatures...Ch. 2.5 - Prob. 35STQCh. 2.5 - Give a Java statement that will display a dialog...Ch. 2.5 - Give a Java statement that, when executed, will...Ch. 2.5 - Prob. 38STQCh. 2.5 - Write a complete Java program that produces a...Ch. 2.5 - Write a complete Java program that behaves as...Ch. 2 - Write a program that demonstrates the approximate...Ch. 2 - Write a program that demonstrates type casting of...Ch. 2 - Write a program that demonstrates the operator %...Ch. 2 - If u = 2, v = 3, w = 5, x = 7, and y = 11, what is...Ch. 2 - What changes to the ChangeMaker program in Listing...Ch. 2 - If the int variable x contains 10, what will the...Ch. 2 - Write some Java statements that use the String...Ch. 2 - Prob. 8ECh. 2 - Prob. 9ECh. 2 - Write a single Java statement that will display...Ch. 2 - What does the Java code Scanner keyboard = new...Ch. 2 - What does the Java code Scanner keyboard = new...Ch. 2 - Prob. 13ECh. 2 - Many sports have constants embedded in their...Ch. 2 - Prob. 15ECh. 2 - Define named constants that you could use in...Ch. 2 - Write a program that reads three whole numbers and...Ch. 2 - Write a program that uses Scanner to read two...Ch. 2 - Write a program that reads the amount of a monthly...Ch. 2 - Write a program that reads a four-digit integer,...Ch. 2 - Prob. 5PCh. 2 - Prob. 6PCh. 2 - Write a program that converts degrees from...Ch. 2 - Write a program that reads a line of text and then...Ch. 2 - Write a program that will read a line of text as...Ch. 2 - Write a program that asks the user to enter a...Ch. 2 - Write a program that determines the change to be...Ch. 2 - Write a program that reads a 4-bit binary number...Ch. 2 - Prob. 7PPCh. 2 - The Harris-Benedict equation estimates the number...Ch. 2 - Repeat any of the previous programming projects...Ch. 2 - Write a program that reads a string for a date in...Ch. 2 - It is important to consider the effect of thermal...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What is the advantage of using a sentinel?
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Write a for loop that displays your name 10 times.
Starting Out with Java: Early Objects (6th Edition)
Write a loop equivalent to the for loop above without using .
C Programming Language
What is the difference between the names defined in an ML let construct from the variables declared in a C bloc...
Concepts of Programming Languages (11th Edition)
State whether each of the following is true or false. A set of statements contained within a pair of parenthese...
Java How To Program (Early Objects)
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
- The following code is in Java:Assume the following declaration exists: enum Coffee { MEDIUM, DARK, DECAF } 1. How can the error in the following code be fixed? Coffee myCup = DARK; switch (myCup) { case Coffee.MEDIUM : System.out.println("Mild flavor."); break; case Coffee.DARK : System.out.println("Strong flavor."); break; case Coffee.DECAF : System.out.println("Won't keep you awake."); break; default: System.out.println("Never heard of it.");arrow_forwardWrite a Java program that lets the user enter the monthly interest rate, number of years, and loan amount, and computes monthly payment and total payment and print both results each on a separate line. The total payment = monthlyPayment * 12 * numberOfYears monthy payment = (loan amount)*(monthy interest rate)/(1 - (1/(1+monthly interest rate)^(number of years * 12)))arrow_forwardTo increment a variable x in Java, we code the following: x=x+1; x++; x+=1; All of the above are correct.arrow_forward
- In JavaFind the value of x , y after the statements are executed: y=10; x=0;test=2>2 || 6>4;if (!test)if (test) y=++x;y=y+2+ x++;arrow_forward2. Write a java program that ask user to enter the grade depending on the below grading system :a. Under 50-F c. 50 to 60 - D d. 60 to 70 - C e. 70 to 80 -Bf. more than 80 - A after that print the equivalent gradearrow_forwardWrite Java statements that output Male if the gender is ‘M’, Female if the gender is ‘F’ and invalid gender otherwise.arrow_forward
- What is the output of the following two lines of Java code?System.out.println("2 + 2 = " + (2 + 2));System.out.println("2 + 2 = " + 2 + 2);arrow_forwardOutput a half pyramid of stars with a height determined by the user. If the user enters a number less than one, exit. Write in java that will results like test case examplesarrow_forwardIn Java, If a = 4; and b = 3;,then after the statement a = b; executes, the value of b is 4 and the value of a is 3. True or Falsearrow_forward
- In Java Determine the output of the following code. boolean done = false; if (done = false) System.out.println("Not"); if( done = true) System.out.println("Done "); else System.out.println("Undecided "); System.out.println("End");arrow_forwardIn Java, what will the following statement output? System.out.println("Hello " + 2 + 0 + 1 + 9 + "!");arrow_forwardWrite a java program that asks the user to enter the number of laps that they have run around a racetrack. Then, prompt the user to enter the time of each lap (in minutes). The program should calculate and display the fastest lap and the average lap time of all laps.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
The Top Down Approach to Software Development; Author: Christopher Kalodikis;https://www.youtube.com/watch?v=v9M8LA2uM48;License: Standard YouTube License, CC-BY