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…
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.
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
>>>
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 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_forwardTask 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_forward
- Write 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_forwardWrite 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_forward
- Statistics 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_forwardWhen analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This adjustment can be done by normalizing to values between 0 and 1, or throwing away outliers. For this program, adjust the values by dividing all values by the largest value. The input begins with an integer indicating the number of floating-point values that follow. Output each floating-point value with two digits after the decimal point, which can be achieved as follows:print('{:.2f}'.format(your_value)) what would be the code?arrow_forward
- Write a program that reads an integer and displays its first five multiples. For example, if the input integer is 10, the output should be as follows: 10, 20, 30, 40, 50.arrow_forwardPRACTICE Write a MATLAB program that asks the user to enter a number. Your program should do the following tasks: • (1) Counts the number of digits in that number; • (2) Displays the sum of the digits; • (3) Checks whether the number is a multiple of the sum; • (4) Prints the number in a reverse order; • (5) Saves the reverse of the number into another variable and displays the reversed number.arrow_forwardA number is a palindrome if its reversal is the same as itself. An even palindrome number is a number which is even and also a palindrome. Write a program that displays the first 50 even palindrome numbers. Display 5 numbers per line and align the numbers properly.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY