a.
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
Yes, the printMax method in Lisiting 7.5 can be invoked by using the following statement.
printMax(new double[]{1,...
c.
Explanation of Solution
No, the printMax method in Lisiting 7.5 cannot be invoked by using the following statement.
printMax(new int[]{1, 2, 3});;
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
- 3. Replace the (????) with relevant code to run the program. Details about the program have been given below. (Java has been used) This program should display: Before: 27 19 34 5 12 After: 0 19 34 5 12 After: 0 0 34 5 12 */ package finalexamtakehome6; public class Finalexamtakehome6 { // public void print ( int[] x ) { while ( int j=0; j < x.length; j++ ) System.out.print( x[0] + " " ); System.out.println( ); } public void changeElement ( int[] x, int elt ) { if ( elt x.length ) x[ elt ] = 0; } // public static void main(String[] args) { Finalexamtakehome6 cng = new Finalexamtakehome6(); int[] value = {27, 19, 34, 5, 12} ; int chgelt = 0; System.out.println( "Before:" ); cng.print( value ); cng.changeElement( value, chgelt ); System.out.println( "After:" ); cng.print( value ); chgelt =…arrow_forwardChapter 5. PC #17. Rock, Paper, Scissors Game (page 317) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. Add the following two lines to the beginning of your main method. This will allow your computer choices match with the test cases here in HyperGrade. long seed = Long.parseLong(args[0]); Random random = new Random(seed); 2. When the program begins, a random number in the range of 0 through 2 is generated. If the number is 0, then the computer has chosen rock. If the number is 1, then the computer has chosen paper. If the number is 2, then the computer has chosen scissors. (Do not display the computer choice yet.) 3. The user enters his or her choice of "rock", "paper", or "scissors" at the keyboard. You should use 1 for rock, 2 for paper, and 3 for scissors. Internally, you can store 0, 1, and 2 as the user choice, to match with the above schema. 4. Both user and computer choices…arrow_forwardChapter 5. PC #17. Rock, Paper, Scissors Game (page 317) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. Add the following two lines to the beginning of your main method. This will allow your computer choices match with the test cases here in HyperGrade. long seed = Long.parseLong(args[0]); Random random = new Random(seed); 2. When the program begins, a random number in the range of 0 through 2 is generated. If the number is 0, then the computer has chosen rock. If the number is 1, then the computer has chosen paper. If the number is 2, then the computer has chosen scissors. (Do not display the computer choice yet.) 3. The user enters his or her choice of "rock", "paper", or "scissors" at the keyboard. You should use 1 for rock, 2 for paper, and 3 for scissors. Internally, you can store 0, 1, and 2 as the user choice, to match with the above schema. 4. Both user and computer choices…arrow_forward
- Chapter 5. PC #17. Rock, Paper, Scissors Game (page 317) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. Add the following two lines to the beginning of your main method. This will allow your computer choices match with the test cases here in HyperGrade. long seed = Long.parseLong(args[0]); Random random = new Random(seed); 2. When the program begins, a random number in the range of 0 through 2 is generated. If the number is 0, then the computer has chosen rock. If the number is 1, then the computer has chosen paper. If the number is 2, then the computer has chosen scissors. (Do not display the computer choice yet.) 3. The user enters his or her choice of "rock", "paper", or "scissors" at the keyboard. You should use 1 for rock, 2 for paper, and 3 for scissors. Internally, you can store 0, 1, and 2 as the user choice, to match with the above schema. 4. Both user and computer choices…arrow_forwardCould this be done in C++ please? 1. The class should have a two dimensional array of the char or int type as a private variable. The class could have some other private variables as needed. A public constructor must should be used to initialize private variables. Remember that you need two loops to access all rows and columns to initialize each array element. There must be other public functions to do tasks, such as XPlay, OPlay, DetermineAWinner, and others as needed. 2. The main should have a loop to repeat tasks until there is a winner or a tie.arrow_forwardCan you please write the follwing in Java. You will implement this program in a specific way in order to gain some experience with loops, arrays and array lists. Use an array of strings to store the 4 strings listed in the description. Use a do-while loop for your 'game engine'. This means the game starts once the user enters money. The decision to stop occurs at the bottom of the loop. The do-while loop keeps going until the user quits, or there is no money left. The pseudocode for this 'game engine' is shown below: determine the fruits to display (step 3 below) and print them determine if there are 3 or 4 of the same image display the results update the customer balance as necessary prompt to play or quit continue loop if customer wants to play and there's money for another game. Use the Random class to generate a random number between 0 and 3. This random number will be an index into the array of strings. Add the string at that index to an ArrayList. You'll have to do…arrow_forward
- Please use easy logic with proper indentations and comments for understanding!. Coding should be in C++. 3. Define a class which stores up to 10 integer values in an array. The class should also define the following 4 public methods: setNumber – accepts an integer value to store in the array. The value is stored in the next available element of the array (first call to the method stores the value in element 0 with the second call storing the value in element 1.) The method returns true if there is room in the array and the integer was successfully stored. Returns false otherwise. clear – removes all values from the array so that the array can be reused. displayNumbers – displays the values currently stored in the array. getStats – determines the largest, smallest, and average of the values currently stored in the array. These values are returned to the caller via reference parameters. All methods should produce correct results regardless of the order in which…arrow_forwardWhat is the value of x when i = 4? #include int main (void) { int x = for (int i = 0; i <= 4; ++i) { X = X + i; } printf("%d %d", i, x); return 0; }arrow_forwardfill out code /* (name header)*/ /* * Your task is to implement few methods in the class below. The class "Battery" models a rechargeable * battery. The capacity of a battery is measured in milliampere hours. You are required to implement * the instructions below according to the requirements specified in the comments. */ public class Battery extends BatteryTester { /* * Declare data fields: a double named maxCapacity that stores the maximum capacity of AA battery. * a double named curCapacity that stores the current capacity of AA battery */ // Your code here... double maxCapacity; double curCapacity; /* * The capacity of a battery is measured in milliampere hours. A typical * AA battery has a capacity of 2000 to 3000 mAh, * Implement the default constructor. Set the value of the maxCapacity and curCapacity to 3000. */ // Your code here... } /* * Implement the overloaded…arrow_forward
- 1)Write a method that takes an array of ints and returns the sum of all numbers that are even. For example, given an array {3, 4, 6}, you would return 10. 2)For this exercise, you are given an array of integers. Return true if every element in the array is an odd number, otherwise return false. 3) Given an array of strings, return the array in reverse order. For example, given: reverse({"one", "two", "three"}); You would return: {"three", "two", "one"} 4) For this exercise, you need to shift all the elements in the array one space to the right (increase the index of the element by 1). The last element will wrap around and become the new first element. For example, given: moveUp({"first", "second", "third", "fourth"}); You would return: {"fourth", "first", "second", "third"}arrow_forwardWhat is the result of int(4+6/2+2*2)?arrow_forwardthis practice assignment wants me to : Write an application that asks a user to enter an integer. Display a statement that indicates whether the integer is even or odd. it is saying that i am missing a return statement. here is my code: mport java.util.Scanner; class EvenOdd { public static void main(String[] args) { Scanner input = new Scanner(System.in); int number; System.out.println("Enter the integer >>>"); number = input.nextInt(); } public static boolean isEven(int number) { if (number % 2 == 0) System.out.println("The number is even."); else System.out.println("The number is odd."); } }arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning