Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 5, Problem 2AW
Here is the code for the displayValue method, shown earlier in this chapter:
public static void displayValue(int num)
{
System.out,println(“The value is ” + num);
}
For each of the following code segments, indicate whether it will successfully compile or cause an error:
- a. displayValue(100);
- b. displayValue(6.0);
- c. short s = 5;
- 1. displayValue(s);
- d. long num = 1;
- 2. displayValue(num);
- e. displayValue(6.2f);
- f. displayValue((int) 7.5);
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
// This program assigns values to two variables
// and performs mathematical operations with them
public class DebugFour1
{
publicstaticmain(Stringargs[])
{
int x =5
int y =8;
System.out.println("adding " + x + y);
int z =19;
System.out.println("subtracting " + z - y);
System.out.println("dividing " + z / x);
System.out.println("multiplying " + x / z);
}
}
int stop = 6;
int num =6;
int count=0;
for(int i = stop; i >0; i-=2)
{
num += i;
count++;
}
System.out.println("num = "+ num);
System.out.println("count = "+ count);
}
}
PROGRAMMING LANGUAGE: Java
Chapter 5 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 5.1 - Prob. 5.1CPCh. 5.1 - Prob. 5.2CPCh. 5.1 - Prob. 5.3CPCh. 5.1 - What message will the following program display if...Ch. 5.1 - Prob. 5.5CPCh. 5.2 - What is the difference between an argument and a...Ch. 5.2 - Prob. 5.7CPCh. 5.2 - Prob. 5.8CPCh. 5.2 - Prob. 5.9CPCh. 5.2 - What will the following program display? public...
Ch. 5.4 - Prob. 5.11CPCh. 5.4 - Prob. 5.12CPCh. 5.4 - Prob. 5.13CPCh. 5.4 - Prob. 5.14CPCh. 5 - Prob. 1MCCh. 5 - Prob. 2MCCh. 5 - Prob. 3MCCh. 5 - Prob. 4MCCh. 5 - A value that is passed into a method when it is...Ch. 5 - Prob. 6MCCh. 5 - Prob. 7MCCh. 5 - Prob. 8MCCh. 5 - Prob. 9MCCh. 5 - True or False: You terminate a method header with...Ch. 5 - Prob. 11TFCh. 5 - Prob. 12TFCh. 5 - Prob. 13TFCh. 5 - Prob. 14TFCh. 5 - Prob. 15TFCh. 5 - Prob. 16TFCh. 5 - Prob. 17TFCh. 5 - True or False: No two methods in the same program...Ch. 5 - True or False: It is possible for one method to...Ch. 5 - True or False: You must have a return statement in...Ch. 5 - Prob. 1FTECh. 5 - Look at the following method header: public static...Ch. 5 - Prob. 3FTECh. 5 - Prob. 4FTECh. 5 - Prob. 1AWCh. 5 - Here is the code for the displayValue method,...Ch. 5 - Prob. 3AWCh. 5 - What will the following program display? public...Ch. 5 - A program contains the following method...Ch. 5 - Prob. 6AWCh. 5 - Prob. 7AWCh. 5 - Write a method named square that accepts an...Ch. 5 - Write a method named getName that prompts the user...Ch. 5 - Write a method named quartersToDol1ars. The method...Ch. 5 - Prob. 1SACh. 5 - Prob. 2SACh. 5 - What is the difference between an argument and a...Ch. 5 - Where do you declare a parameter variable?Ch. 5 - Prob. 5SACh. 5 - Prob. 6SACh. 5 - Prob. 1PCCh. 5 - Retail Price Calculator Write a program that asks...Ch. 5 - Rectangle AreaComplete the Program If you have...Ch. 5 - Paint Job Estimator A painting company has...Ch. 5 - Prob. 5PCCh. 5 - Celsius Temperature Table The formula for...Ch. 5 - Test Average and Grade Write a program that asks...Ch. 5 - Conversion Program Write a program that asks the...Ch. 5 - Distance TraveLed Modification The distance a...Ch. 5 - Stock Profit The profit from the sale of a stock...Ch. 5 - Multiple Stock Sales Use the method that you wrote...Ch. 5 - Kinetic Energy In physics, an object that is in...Ch. 5 - isPrime Method A prime number is a number that is...Ch. 5 - Prime Number List Use the isPrime method that you...Ch. 5 - Even/Odd Counter You can use the following logic...Ch. 5 - Present Value Suppose you want to deposit a...Ch. 5 - Rock, Paper, Scissors Game Write a program that...Ch. 5 - ESP Game Write a program that tests your ESP...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Each of the following declarations or code segments has errors. Locate as many as possible. A) catch { quotient...
Starting Out with C++: Early Objects (9th Edition)
Define each of the following terms: data definition language data manipulation language referential integrity c...
Modern Database Management
Code an SQL statement that creates a table with all columns from the parent and child tables in your answer to ...
Database Concepts (7th Edition)
What are the two kinds of memory in a computer?
Java: An Introduction to Problem Solving and Programming (7th Edition)
Explain why software testing should always be an incremental, staged activity. Are programmers the best people ...
Software Engineering (10th Edition)
Stock Commission Kathryn bought 750 shares of stock at a price of 35.00 per share. She must pay her stockbroker...
Starting Out with C++ from Control Structures to Objects (9th 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
- The following code results in an error message. What will the error message be andhow can it be fixed? def TryParseInt(p1, p2):return p1 + p2#Calling Codep3 = TryParseInt(10)arrow_forwardPlease add commentsarrow_forwardThe Upper bound limit is 90, lower bound limit is -100. If a value is inputted (not through user but through a test) if the value is greater than 90 return 90. If the value is lower than -100 return -100. If the value is 0 return -1000.arrow_forward
- Greetings. The programming language to be used is: JAVA Please write a GUI that implements a game, where the user has to click the buttons in the order of their numbering. * The 9 buttons are arranged in a grid of 3 by 3. Each one has a different number from 1 to 9. * If the user selects the correct button, it should turn green and become disabled. The score should beincremented by 1. * If the user selects the incorrect button, it should turn red and all the buttons should become disabled. * If the user selects the “Reset” button, all buttons should be white and become enabled, their random numbers should be reassigned and the score set to 0. Thank you.arrow_forwardin this code, the integer on each line shows the line number that is not part of code: what are the parameters of sum: ____ 1 public static int sum(int x, int y){ 2 int z = x +y; 3 return z; 4 } 5 public static void main(String[] args){ 6 … 7 sum(a+2, b); 8 … 9 }arrow_forwardPrint "userNum1 is negative." if userNum1 is less than 0. End with newline. Assign userNum2 with 4 if userNum2 is greater than 9. Otherwise, print "userNum2 is less than or equal to 9.". End with newline. 1 import java.util.Scanner; 2 public class UserNums { public static void main (String [] args) { int userNum1; int userNum2; 4 6. 7 Scanner input userNum1 = 8. = new Scanner(System.in); input.nextInt(); input.nextInt(); 9. 10 userNum2 11 12 V* Your code goes here */ 13 System.out.println("userNum2 is " } 14 + userNum2); 15 16 17 }arrow_forward
- int a = 20% 4; System.out.println ("a = " + a): display Oa = 4.5 Oa-4 Oa= 0 Oa=2arrow_forwardWhat is the final value of y? int x = 4; 6; int y if (x < 10) { if (y < 5) { y = y + 1; } } else { } y = 7; } else { y = y + 10;arrow_forwardUsing C# in Microsoft Visual Studio create an application that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows:1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Do not display the computer’s choice yet.)2. The user selects his or her choice of rock, paper, or scissors. To get this input you can use Button controls, or clickable PictureBox controls displaying some of the artwork that you will find in the student sample files.3. The computer’s choice is displayed.4. A winner is selected according to the following rules:• If one player chooses rock and the other player chooses scissors, then rock wins. (Rock smashes scissors.)• If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors…arrow_forward
- cerat javaFX 9-Rock, Paper, Scissors GameCreate a JavaFX application that lets the user play the game of rock, paper, scissors againstthe computer. The program should work as follows.1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, thenthe computer has chosen paper. If the number is 3, then the computer has chosenscissors. (Do not display the computer’s choice yet.)2. The user selects his or her choice of rock, paper, or scissors by clicking a Button. Animage of the user’s choice should be displayed in an ImageView component. (Youwill find rock, paper, and scissors image files in the book’s Student Sample Files.)3. An image of the computer’s choice is displayed.4. A winner is selected according to the following rules:l If one player chooses rock and the other player chooses scissors, then rock wins.(Rock smashes scissors.)l If one player chooses scissors and the other player…arrow_forwardExercise GradesStatistics (Method): Write a program called GradesStatistics, which reads in n grades (of int between 0 and 100, inclusive) and displays the average, minimum, maximum, median and standard deviation. Display the floating-point values upto 2 decimal places. Your output shall look like:Enter the number of students: 4Enter the grade for student 1: 50Enter the grade for student 2: 51Enter the grade for student 3: 56Enter the grade for student 4: 53{50,51,56,53}The average is: 52.50The median is: 52.00The minimum is: 50The maximum is: 56The standard deviation is: 2.29The formula for calculating standard deviation is:Hints:public class GradesStatistics {public static int[] grades; // Declare an int[], to be allocated later.// This array is accessible by all the methods.public static void main(String[] args) {readGrades(); // Read and save the inputs in int[] gradesprintArray(grades);System.out.println("The average is " + average(grades));System.out.println("The median is " +…arrow_forwardbasic java please Write a void method named emptyBox()that accepts two parameters: the first parameter should be the height of a box to be drawn, and the second parameter will be the width. The method should then draw an empty box of the correct size. For example, the call emptyBox(8, 5) should produce the following output: ***** * * * * * * * * * * * * ***** The width of the box is 5. The middle lines have 3 spaces in the middle. The height of the box is 8. The middle columns have 6 spacesarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Java Math Library; Author: Alex Lee;https://www.youtube.com/watch?v=ufegX5o8uc4;License: Standard YouTube License, CC-BY