Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 2, Problem 3E

Write a program that demonstrates the operator % by performing the following tasks:

  • Use scanner to read a floating-point value x.
  • Compute x % 2.0 and store the result in y.
  • Display x and y clearly labeled.
  • Type cast x to an int value and store the result in z.
  • Display x, z, and z % 2 clearly labeled.

Try your program with positive and negative values of x. What implications do your results have for deciding whether a negative integer is odd?

Blurred answer
Students have asked these similar questions
Write a program that will determine how many of a set of 10 numbers are even and how many are odd. a. Read in one number at a time. b. Compute and display the number of even integers and the number of odd integers. Hint: You can use the modulus operator (%) to determine if each integer is even or od. Your output should look like this: Enter integer: 2 Enter integer: 4 Enter integer: 3 Enter integer: 5 Enter integer: 6 Enter integer: 4 Enter integer: 77 Enter integer: 5 Enter integer: 89 Enter integer: 45 There are even numbers in the list 6 odd numbers in the list 4 There are >>>
Write a program that uses a random number generator to generate a two digit positive integer and allows the user to perform one or more of the following operations:   Double the number. Reverse the digits of the number. Raise the number to the power of 2, 3, or 4. Sum the digits of the number. If the number is a two digit number, then raise the first digit to the power of the second digit. If the number is a three digit number and the last digit is less than or equal to 4, then raise the first two digits to the power of the last digit.   After performing an operation if the number is less than 10, add 10 to the number. Also, after each operation, determine if the number is prime. Each successive operation should be performed on the number generated by the last operation. Your program should not contain any global variables and each of these operations must be implemented by a separate function. Also, your program should be menu driven.     Additional Instructions:   Create an…
OBJECT: Write a program to define two integer variables and assign values to them (you can use any values you like). Then do the following: 1.Compute and print their sum with an appropriate message. 2.Compute and print their product with an appropriate message. 3. Add their sum to their product and print the result with an appropriate message. 4. Compute and print their difference (first - second) with an appropriate message. 5.Compute the quotient of (first / second) and print it with an appropriate message. 6.Compute the remainder of (first % second) and print it with an appropriate message.   INPUT: None   OUTPUT: As specified above.   TOPICS: arithmetic expressions, cout, and assignment statements, program documentation. In C++

Chapter 2 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

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...
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY