Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 7.9, Problem 7.9.1CP
a)
Program Plan Intro
Variable-length argument (varargs):
In a method, the variable-length argument refers the variable number of arguments of same type. A method can contain only one variable-length parameter and the parameter must be the last parameter in the method.
Syntax:
Syntax to refer the variable-length argument is as follows:
typeName... parameterName
Example:
//variable length argument
double… num
b)
Explanation of Solution
Given Header:
public static void print(double... numbers, String... name)
Wrong with the given method header:
c)
Explanation of Solution
Given Header:
public static double... print(double d1, double d2)
Wrong with the given method header:
The return t...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Question P Print person1's kids, call the incNumKids() method, and print again, outputting text as below. End each line with a newline. Sample output for below program with input 3: Kids: 3 New baby, kids now: 4
// ===== Code from file PersonInfo.java =====public class PersonInfo {private int numKids;
public void setNumKids(int setPersonsKids) {numKids = setPersonsKids;}
public void incNumKids() {numKids = numKids + 1;}
public int getNumKids() {return numKids;}}// ===== end =====
// ===== Code from file CallPersonInfo.java =====import java.util.Scanner;
public class CallPersonInfo {public static void main(String [] args) {Scanner scnr = new Scanner(System.in);PersonInfo person1 = new PersonInfo();int personsKid;
personsKid = scnr.nextInt();
person1.setNumKids(personsKid);
/* Your solution goes here */
}}// ===== end =====
Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this…
Find out the output of the following code snippet?
class OverloadingCalculation3{
void sum(int a,long b){System.out.printin("a method invoked");}
void sum(long a,int b){System.out.printin("b method invoked");}
public static void main(String args[]){
OverloadingCalculation3 obj=new OverloadingCalculation3 () ;
obj.sum(20,20);
}
}
Print person1's kids, call the incNumKids() method, and print again, outputting text as below. End each line with a newline.Sample output for below program with input 3:
Kids: 3
New baby, kids now: 4
// ===== Code from file PersonInfo.java =====public class PersonInfo {private int numKids;
public void setNumKids(int setPersonsKids) {numKids = setPersonsKids;}
public void incNumKids() {numKids = numKids + 1;}
public int getNumKids() {return numKids;}}// ===== end =====
// ===== Code from file CallPersonInfo.java =====import java.util.Scanner;
public class CallPersonInfo {public static void main(String [] args) {Scanner scnr = new Scanner(System.in);PersonInfo person1 = new PersonInfo();int personsKid;
personsKid = scnr.nextInt();
person1.setNumKids(personsKid);
/* Your solution goes here */
}}// ===== end =====
Chapter 7 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 7.2 - Prob. 7.2.1CPCh. 7.2 - Prob. 7.2.2CPCh. 7.2 - What is the output of the following code? int x =...Ch. 7.2 - Indicate true or false for the following...Ch. 7.2 - Which of the following statements are valid? a....Ch. 7.2 - Prob. 7.2.6CPCh. 7.2 - What is the array index type? What is the lowest...Ch. 7.2 - Write statements to do the following: a. Create an...Ch. 7.2 - What happens when your program attempts to access...Ch. 7.2 - Identify and fix the errors in the following code:...
Ch. 7.2 - What is the output of the following code? 1....Ch. 7.4 - Will the program pick four random cards if you...Ch. 7.5 - Use the arraycopy method to copy the following...Ch. 7.5 - Prob. 7.5.2CPCh. 7.7 - Suppose the following code is written to reverse...Ch. 7.8 - Prob. 7.8.1CPCh. 7.8 - Prob. 7.8.2CPCh. 7.9 - Prob. 7.9.1CPCh. 7.9 - Prob. 7.9.2CPCh. 7.10 - If high is a very large integer such as the...Ch. 7.10 - Prob. 7.10.2CPCh. 7.10 - Prob. 7.10.3CPCh. 7.11 - Prob. 7.11.1CPCh. 7.11 - How do you modify the selectionSort method in...Ch. 7.12 - What types of array can be sorted using the...Ch. 7.12 - To apply java.util.Arrays.binarySearch (array,...Ch. 7.12 - Show the output of the following code: int[] list1...Ch. 7.13 - This book declares the main method as public...Ch. 7.13 - Show the output of the following program when...Ch. 7 - (Assign grades) Write a program that reads student...Ch. 7 - (Reverse the numbers entered) Write a program that...Ch. 7 - (Count occurrence of numbers) Write a program that...Ch. 7 - (Analyze scores) Write a program that reads an...Ch. 7 - (Print distinct numbers) Write a program that...Ch. 7 - (Revise Listing 5.1 5, PrimeNumber.java) Listing...Ch. 7 - (Count single digits) Write a program that...Ch. 7 - (Average an array) Write two overloaded methods...Ch. 7 - (Find the smallest element) Write a method that...Ch. 7 - Prob. 7.10PECh. 7 - (Statistics: compute deviation) Programming...Ch. 7 - (Reverse an array) The reverse method in Section...Ch. 7 - Prob. 7.13PECh. 7 - Prob. 7.14PECh. 7 - 7 .15 (Eliminate duplicates) Write a method that...Ch. 7 - (Execution time) Write a program that randomly...Ch. 7 - Prob. 7.17PECh. 7 - (Bubble sort) Write a sort method that uses the...Ch. 7 - (Sorted?) Write the following method that returns...Ch. 7 - (Revise selection sort) In Listing 7 .8, you used...Ch. 7 - (Sum integers) Write a program that passes an...Ch. 7 - (Find the number of uppercase letters in a string)...Ch. 7 - (Game: locker puzzle) A school bas 100 lockers and...Ch. 7 - (Simulation: coupon collectors problem) Coupon...Ch. 7 - (Algebra: solve quadratic equations) Write a...Ch. 7 - (Strictly identical arrays) The arrays 1ist1 and...Ch. 7 - (Identical arrays) The arrays 1ist1 and 1ist2 are...Ch. 7 - (Math: combinations) Write a program that prompts...Ch. 7 - (Game: pick four cards) Write a program that picks...Ch. 7 - (Pattern recognition: consecutive four equal...Ch. 7 - (Merge two sorted Lists) Write the following...Ch. 7 - (Partition of a list) Write the following method...Ch. 7 - Prob. 7.33PECh. 7 - (Sort characters in a string) Write a method that...Ch. 7 - (Game: hangman) Write a hangman game that randomly...Ch. 7 - (Game: Eight Queens) The classic Eight Queens...Ch. 7 - Prob. 7.37PE
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
- What does the following program print? 1 public static void main(String[] args) 2 { 3 int a = 3; 4 int b = 2; 5 int c = 4; 6 if (a < b) 7 { 8 if (b < c)arrow_forwardWrite a method with the following header to display an integer in reverse order: public static void reverse(int number) For example, reverse(3456) displays 6543. Write a test program that prompts the user to enter an integer then displays its reversalarrow_forwardwrite a program that reads the followinginformation and prints a payroll statement.Employee’s name (e.g., Smith)Number of hours worked in a week (e.g., 10)Hourly pay rate (e.g., 9.75)Federal tax withholding rate (e.g., 20%)State tax withholding rate (e.g., 9%) In summary, design a program to• Prompt user for 5 values and read the values using Scannero Use method .nextLine() to get the String for the nameo Use method .nextDouble() to get all other numeric values• Calculating the Gross payo Gross pay = hours worked * hourly pay rate• Calculating the Federal withholdingo Federal withholding = Gross pay * federal tax withholding rate• Calculating the State withholdingo State withholding = Gross pay * state tax withholding rate• Calculating the Total deductiono Total deduction = Federal withholding + State withholding• Calculating the Net Payo Net Pay = Gross pay – Total deduction• Formatting the output same as the Sample run (Use ONLY printf)o Correctly format 2 decimals and use $ (hint…arrow_forward
- In the following code snippet, what is the scope of variable b?public static void m1(){ int i = 0; double b = 0;}public static void m2(){ double a = 10 + 1;}public static void main(String[] args){ m1(); m2();}arrow_forwardin this code, the integer on each line shows the line number that is not part of code: what is the signature of the method 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_forwardWrite a method that prints numbers using the following header:public static void printNumbers(int num1, int num2, intnumberPerLine)This method prints the characters between num1 and num2 with the specifiednumbers per line. Write a test program that prints ten characters per line from 1to 100. Numbers are separated by exactly one space.arrow_forward
- Using Java, Write a method named isEven that accepts an int argument. The method should return true if the argument is even, or false otherwise. Also write a program to test your method.arrow_forwardWrite a method with the following header to format the integerwith the specified width.public static String format(int number, int width)The method returns a string for the number with one or more prefix 0s. The size of thestring is the width. For example, format(34, 4) returns 0034 and format(34,5) returns 00034. If the number is longer than the width, the method returns thestring representation for the number. For example, format(34, 1) returns 34.Write a test program that prompts the user to enter a number and its width, anddisplays a string returned by invoking format(number, width).arrow_forwardConsider the method below, what will be printed if calling test_b(4)? public static void test_b(int n) { if (n>0) test_b(n-2); System.out.println(n + " "); }arrow_forward
- Create a method that takes a value and tell whether it is null or not.Declared as: boolean isZero (float a)arrow_forwardWhat is the output of the following program and show all your workings? public class Main{public static void main(String[] args) {System.out.printin(mystery(5));}static int mystery(int num){if(num <= 1)return 1;else{return mystery(num-1) + mystery(num—2) ;}arrow_forwardwrite a method in class String that returns the reserved version of the current String(in java) here's the method signature public static int ceiling (double num) { return num <=0? (int) num : (int) num +1; }arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage