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
Question
Chapter 7.3, Problem 19STQ
Program Plan Intro
Array: An array is a container which is used to hold a set of variables of the similar data type.
Creating an array:
- • User can create an array in the similar way that user creating an object of a class type with the help of “new” operation.
- • Syntax for creating an array is given below:
dataType[] array_name = new dataType[Length];
From the above syntax,
- ○ The “dataType” represents “int”, “double”, “char” and so on.
- ○ The “array_name” indicates name of array that is given by user.
- ○ The “Length” defines the number of elements that the array can store.
Example:
The example for creating an array is given below:
int[] arr = new int[4];
The above array declaration is used to store “4” integer values.
- • In the above example, the “dataType” is “int”, the “array_name” is “arr” and the “Length” is “4”.
- • Indices of array always begin with “0”.
- ○ For array “arr”, index are “arr[0]”, “arr[1]”, “arr[2]” and “arr[3]”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The index type of an array may be any kind of data. Do you believe this to be true?
What is the array index type? What is the lowest index? What is the representation of the third element in an array named a?
Try using the ref or out keyword to pass in an array argument and see what happens.
Chapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - Consider the following array: int [] a = new...Ch. 7.1 - What is wrong with the following code to...Ch. 7.1 - Write a complete Java program that reads 20 values...Ch. 7.2 - Write some Java code that will declare an array...Ch. 7.2 - Rewrite the method displayResults of the program...Ch. 7.2 - What output will be produced by the following...Ch. 7.2 - Give the definition of a static method called...
Ch. 7.2 - Give the definition of a static method called...Ch. 7.2 - Prob. 12STQCh. 7.2 - The following method compiles and executes but...Ch. 7.2 - Suppose that we add the following method to the...Ch. 7.3 - Prob. 15STQCh. 7.3 - Replace the last loop in Listing 7.8 with a loop...Ch. 7.3 - Suppose a is an array of values of type double....Ch. 7.3 - Suppose a is an array of values of type double...Ch. 7.3 - Prob. 19STQCh. 7.3 - Consider the partially filled array a from...Ch. 7.3 - Repeat the previous question, but this time assume...Ch. 7.3 - Write an accessor method getEntryArray for the...Ch. 7.4 - Prob. 23STQCh. 7.4 - Write the invocation of the method selectionSort...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - Consider an array b of int values in which a value...Ch. 7.5 - What output is produced by the following code?...Ch. 7.5 - Revise the method showTable in Listing 7.13 so...Ch. 7.5 - Write code that will fill the following array a...Ch. 7.5 - Write a void method called display such that the...Ch. 7.6 - Prob. 33STQCh. 7 - Write a program in a class NumberAboveAverage that...Ch. 7 - Write a program in a class CountFamiles that...Ch. 7 - Write a program in a class CountPoor that counts...Ch. 7 - Write a program in a class FlowerCounter that...Ch. 7 - Write a program in a class characterFrequency that...Ch. 7 - Create a class Ledger that will record the sales...Ch. 7 - Define the following methods for the class Ledger,...Ch. 7 - Write a static method isStrictlyIncreasing (double...Ch. 7 - Write a static method removeDuplicates(Character[]...Ch. 7 - Write a static method remove {int v, int [] in}...Ch. 7 - Suppose that we are selling boxes of candy for a...Ch. 7 - Create a class polynomial that is used to evaluate...Ch. 7 - Write a method beyond LastEntry (position) for the...Ch. 7 - Revise the class OneWayNoRepeatsList, as given in...Ch. 7 - Write a static method for selection sort that will...Ch. 7 - Overload the method selectionSort in Listing 7.10...Ch. 7 - Revise the method selectionSort that appears in...Ch. 7 - Prob. 18ECh. 7 - Write a sequential search of an array of integers,...Ch. 7 - Write a static method findFigure (picture,...Ch. 7 - Write a static method blur (double [] [] picture)...Ch. 7 - Write a program that reads integers, one per line,...Ch. 7 - The following code creates a small phone book. An...Ch. 7 - Write the method rotateRight that takes an array...Ch. 7 - The following code creates a ragged 2D array. The...Ch. 7 - Write a program that will read a line of text that...Ch. 7 - Prob. 2PPCh. 7 - Add a method bubbleSort to the class ArraySorter,...Ch. 7 - Add a method insertionSort to the class...Ch. 7 - The class TimeBook in Listing 7.14 is not really...Ch. 7 - Define a class called TicTacToe. An object of type...Ch. 7 - Repeat Programming Project 10 from Chapter 5 but...Ch. 7 - Prob. 8PPCh. 7 - Write a GUI application that displays a picture of...Ch. 7 - ELIZA was a program written in 1966 that parodied...Ch. 7 - Prob. 11PPCh. 7 - Create a GUI application that draws the following...Ch. 7 - Practice Program 2 used two arrays to implement a...Ch. 7 - Practice Program 5.4 asked you to define Trivia...
Knowledge Booster
Similar questions
- someone help me modify the code please. Instructions: In the code editor, you are provided with the main() function that asks the user for 10 elements that represents the options for the ring as well as a single integer value that represents the ring that she wants. Then, a call to the findRing() function is made and the array of rings and the ring she wants are passed into it. Your task is to implement the findRing() function. This has the following details: Return type - int Name - findRing Parameters int* - for the array of rings int - size of the array of rings int - the ring that she wants Return value - the index of the ring in the array of rings. It is guaranteed that there is only one such ring that matches the ring that she wants. Input 1. Ten integer values representing the rings 2. Integer value representing the ring she wants #include <stdio.h>int findRing(int rings[],int n,int wantedRing){int index=0; for(int i=0;i<n;i++) {…arrow_forwardThe index type of an array may be of any data type. Do you accept this as true?arrow_forwarddespite that the array parameter is preceded by the const qualifier, the array elements can be modified in the function body. Select one: True Falsearrow_forward
- check the image for questionarrow_forwardhow do we return a pointer to the new array?arrow_forwardWhich of the following are true about arrays? Arrays are reference types. Array indexing is bounds‐checked. Arrays sometimes can be created without using new. The entire contents of an array can be copied via =.arrow_forward
- Write a program which has a class called Character and data member which is a pointer to a character. Use appropriate data members to get input from the user and to perform linear search to locate an element in array.arrow_forwardWhat is an example of an array with 5 elements in it?arrow_forwardDeclare a MyStruct variable and initialize the second field to an array containing all zeros.arrow_forward
- D. The method construct will receive four parameters: an integer k, and three arrays called old1, old2, and sumarr. The method will construct the first k elements of the sumarr array fromt the first k elements of the oldi and old2 arrays, as follows. Each element of sumarr will be equal to the sum of the corresponding elements of gldi and gld2. For example, sumarri0] will be old1[0]+old2[0], sumarr[1] will be old1[1] + old2[1] and so on. (You are using parallel arrays.) Write a complete Java program to do the following: the main program will call a series of methods to process a set of data. One method will read data into two arrays. A second method will print the values stored in an array. A third method will find the smallest of the values stored in an array. A fourth method will construct a new array from two existing arrays. A fifth method will compare the values in the two arrays. Use files for both input and output. Be sure to pass the file variable to any method that will need…arrow_forwardPlease help me with this.arrow_forwardD. The method construct will receive four parameters: an integer k and three arrays called old1, old2, and sumarr. The method will construct the first k elements of the sumarr array fromt the first k elements of the oldi and old2 arrays, as follows. Each element of sumarr will be equal to the sum of the corresponding elements of gldi and gld2. For example, sumarri0] will be old1[0]+old2[0], sumarr[1] will be old1[1] + old2[1] and so on. (You are using parallel arrays.) Write a complete Java program to do the following: the main program will call a series of methods to process a set of data. One method will read data into two arrays. A second method will print the values stored in an array. A third method will find the smallest of the values stored in an array. A fourth method will construct a new array from two existing arrays. A fifth method will compare the values in the two arrays. Use files for both input and output. Be sure to pass the file variable to any method that will need…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT