Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 2, Problem 2E
Write a
- Use scanner to read a floating-point value x.
- Type cast x to an int value and store the result in y.
- Display x and y clearly labeled.
- Type cast x to a byte value and store the result in z.
- Display x and z clearly labeled.
Try your program with positive and negative values of x that range in magnitude from 2e-11 to 2e11. What can you conclude?
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a program that prompts the user to input any digit then swap the position of the first and the last digit. Next, the user will be prompt to select what arithmetic operation he/she want to employ on the first and last digit based on the following choices:
1. Sum of their square
2. Product of their square root
3. Square of their product
The output will display the result of the arithmetic operation followed by the digit with a swapped position of “first” and “last” digit. Then finally display the equivalent uppercase alphabet for the first digit and lowercase alphabet for the last digit respectively after swapping.
Note:
1. If the last digit of the inputted digit from the user is zero, it must display that there is no equivalent alphabet for that digit.
2. If the user chooses arithmetic operation No.2, format the output to three decimal places
TEST CASES:
If a user inputs a digit and choose arithmetic operation No.1:
Input any number: 97834
Select an arithmetic operation…
Summary: Given integer values for red, green, and blue, subtract the gray from each value.
Computers represent color by combining the sub-colors red, green, and blue (rgb). Each sub-color's value can range from 0 to 255.
Thus (255, 0, 0) is bright red, (130, 0, 130) is a medium purple, (0, 0, 0) is black, (255, 255, 255) is white, and (40, 40, 40) is a dark gray.
(130, 50, 130) is a faded purple, due to the (50, 50, 50) gray part. (In other words, equal amounts of red, green, blue yield gray).
Given values for red, green, and blue, remove the gray part.
Ex: If the input is:
130
50
130
the output is:
80 0 80
Find the smallest value, and then subtract it from all three values, thus removing the gray.
Note: This page converts rgb values into colors.
461710.3116374.qx3zqy7
LAB
ACTIVITY
1
111
4.10.1: LAB: Remove gray from RGB
Type your code here.
111
main.py
0/10
Load default template...
Write a program that calculates the equivalent resistance of a circuit. n electrical resistors with
resistance values R1, R2,.., Rn are said to be connected in parallel if the same voltage is applied
across each. Their equivalent resistance Reg is related to the values R1, R2, ...,
Rn by:
1
1
1
1
+
+...+
R R R,
R.
"eq
Write a program that prompts the user to enter the resistance of n resistors. The user should
be prompted continuously by using a while loop until a zero or negative value is entered (the
program should count the number of resistors n entered by the user and store the values in an
array). Use another separate loop to print the resistance values entered by the user and the
equivalent resistance Reg. Test your program with R1= 1 kn, R2= 2 kn, R3= 4 kQ and R4= 8 kQ.
Chapter 2 Solutions
Java: An Introduction to Problem Solving and Programming (7th 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
Describe two properties that each candidate key must satisfy.
Modern Database Management
Determine the block sizes and header values that would result from the following sequence of malloc requests. A...
Computer Systems: A Programmer's Perspective (3rd Edition)
What would be the output in Self-Test Exercise 6 if the assignment were changed to the following? int extra = 0...
Problem Solving with C++ (9th Edition)
What is a compiler?
Absolute Java (6th Edition)
Write an IfThen statement that sets the variable intFees to 50 when the Boolean variable blnIsMax equals True.
Starting Out With Visual Basic (7th Edition)
A superclass has the following method: public void setValue( int v) { value = v; } Write a statement that may a...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
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
- 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 >>>arrow_forward. Write a program that generates and prints 50 random integers, each between 3 and 6. .Write a program that generates a random number, x, between 1 and 50, a random number y between 2 and 5, and computes x". .Write a program that generates a random number between 1 and 10 and prints your name that many times. .Write a program that generates a random decimal number between 1 and 10 with two decimal places of accuracy. Examples are 1.23, 3.45, 9.80, and 5.00.arrow_forwardWrite a program that reads an integer and displays all its smallest factors, also known as prime factors. For example, if the input integer is 120, the output should be as follows: 2, 2, 2, 3, 5arrow_forward
- Task Write a MASM program that will resemble a digital clock. The clock will display hh:mm:ss (hour, minute and second format; 2 digits for each), i.e., 03:10:05. The clock will take an input from the user (0 to 9) which will be the starting time of the clock. Say the input is 6, so the clock start time is 00:00:06. 00:00:59. You increment the second by one, i.e., 00:00:06, 00:00:07, Then you need to change the minute to 01 and second to 00, i.e., 00:01:00. Similarly, change the time for hour e.g., 00:59:59 will change to 01:00:00. It is a 12 hour clock. After 11:59:59, the clock will change to 00:00:00. You may like to run the attached Calcul.exe to understand the expectation. ● Commenting Most of the lines of the program code should be commented (short comment is fine) so that your code could be well understood.arrow_forwardWrite a program that uses a random number generator to generatea two digits positive integer and allows the user to perform one or moreof the following operations:a. Double the number.b. Reverse the digits of the number.c. Raise the number to the power of 2, 3, or 4.d. Sum the digits of the number.e. If the number is a two digits number, then raise the first digitto the power of the second digit.f. If the number is a three digits number and the last digit is lessthan or equal to 4, then raise the first two digits to the power ofthe last digitarrow_forwardWrite a program that performs as a very simple calculator. Your calculator should be able to handle the four basic math operations — add, subtract, multiply, and divide — on two input values. Your program should prompt the user to enter three arguments: two double values and a character to represent an operation. If the entry arguments are 35.6, 24.1, and '+', the program output should be The sum of 35.6 and 24.1 is 59.7.arrow_forward
- Use Java Programming Given the input n, make a Z pattern using the z character. However, you can only form the pattern "z" if n is odd. If n is even, get the next off number from it (6 to 7) and from that odd number, form the pattern "z"arrow_forwardWrite a program that asks for two numbers. After the input of two numbers, ask the user whatoperation to do between the numbers. Perform the operation according to the user’s choice and displaythe result. After the display, ask the user if he wants to continue. If the user continues, ask for a numberand an operation. Perform the selected operation with the recent result and the new input value. Displaythe result according to the user’s choice and ask the user again if he wants to continue. Repeat thisprocess as long as the user wants to continue.When selecting an operation, it must be case sensitive. If the user provides an invalid input in selectingan operation, display an error message and ask again for an operation. The program must not exit. Theprogram will only terminate after the user select not to continue.arrow_forwardWrite a program that reads an integer and displays all its smallest factors in an increasing order. For example, if the input integer is 120, the output should be as follows: 2, 2, 2, 3, 5.arrow_forward
- Write a program that defines variables a, b, c, d as float and Num2 as integer. Solve the following expression on notebook by supposing some values of each variable, then execute your program for the same values and see the difference if any.a * (b - c / d) + ++ Num2 where a, b, c and d are float type variables.b) Write a program that defines variables Num1, Num2, Num3, and Num, as integer Solve the following expression on notebook by supposing some values of each variable, then execute your program for the same values and see the difference if any.Result= Num1 + Num2 / Num3 + Num + Num2++ where Num1, Num2 and Num3 are all integer type variablesc) Write a program that defines variables m, n, p, and amount, as integer Solve the following expression on notebook by supposing some values of each variable, then execute your program for the same values and see the difference if any.(m + n) / (p + amountarrow_forwardStatistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative floating-point numbers as input, and outputs the max and average, respectively. Output the max and average with two digits after the decimal point. Ex: If the input is: 14.25 25 0 5.75 the output is: 25.00 11.25arrow_forwardWrite a program that performs arithmetic division. The program will use two integers, a and b (obtained by the user) and will perform the division a/b, store the result in another integer c and show the result of the division using cout. In a similar way, extend the program to add, subtract, multiply, do modulo and power using integers a and b. Modify your program so that when it starts, it asks the user which type of calculation it should do, then asks for the 2 integers, then runs the user selected calculation and outputs the result in a user friendly formatted manner.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
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY