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
Expert Solution & Answer
Chapter 7, Problem 3FTE
Explanation of Solution
Given code:
// Array declaration
int[] table = new int[10]; // Line 1
// Loop to read the array
for (int x = 1; x <= 10; x++)// Line 2
{
// assigning value
table[x] = 99; // Line 3
}
Errors in the given code:
The error is present in the Line 2,
- The initialization of “x” is the error in the “for” loop statement.
- “x” is initialized with 1, so it neglects the first value present in the array...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
char[ ] letters=new char[5];int x = 0;while(x < 10){ar[x]='a';x++;}
int* p:
int a[3]{1, 2, 3};
p = a;
What is the value of *(p+2)?
Q1
#include <stdio.h>
int arrC[10] = {0};
int bSearch(int arr[], int l, int h, int key);
int *joinArray(int arrA[], int arrB[])
{
int j = 0;
if ((arrB[0] + arrB[4]) % 5 == 0)
{
arrB[0] = 0;
arrB[4] = 0;
}
for (int i = 0; i < 5; i++)
{
arrC[j++] = arrA[i];
if (arrB[i] == 0 || (bSearch(arrA, 0, 5, arrB[i]) != -1))
{
continue;
}
else
arrC[j++] = arrB[i];
}
for (int i = 0; i < j; i++)
{
int temp;
for (int k = i + 1; k < j; k++)
{
if (arrC[i] > arrC[k])
{
temp = arrC[i];
arrC[i] = arrC[k];
arrC[k] = temp;
}
}
}
for (int i = 0; i < j; i++)
{
printf("%d ", arrC[i]);
}
return arrC;
}
int bSearch(int arr[], int l, int h, int key)
{
if (h >= l)
{
int mid = l + (h - l) / 2;
if…
Chapter 7 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 7.1 - Write statements that create the following arrays:...Ch. 7.1 - Whats wrong with the following array declarations?...Ch. 7.1 - Prob. 7.3CPCh. 7.1 - Prob. 7.4CPCh. 7.1 - Prob. 7.5CPCh. 7.1 - Prob. 7.6CPCh. 7.1 - Prob. 7.7CPCh. 7.1 - Prob. 7.8CPCh. 7.2 - Prob. 7.9CPCh. 7.2 - Prob. 7.10CP
Ch. 7.2 - A program has the following declaration: double[]...Ch. 7.2 - Look at the following statements: int[] a = { 1,...Ch. 7.3 - Prob. 7.13CPCh. 7.3 - Write a method named zero, which accepts an int...Ch. 7.6 - Prob. 7.15CPCh. 7.7 - Recall that we discussed a Rectangle class in...Ch. 7.10 - Prob. 7.17CPCh. 7.11 - What value in an array does the selection sort...Ch. 7.11 - How many times will the selection sort swap the...Ch. 7.11 - Prob. 7.20CPCh. 7.11 - Prob. 7.21CPCh. 7.11 - If a sequential search is performed on an array,...Ch. 7.13 - What import statement must you include in your...Ch. 7.13 - Write a statement that creates an ArrayList object...Ch. 7.13 - Write a statement that creates an ArrayList object...Ch. 7.13 - Prob. 7.26CPCh. 7.13 - Prob. 7.27CPCh. 7.13 - Prob. 7.28CPCh. 7.13 - Prob. 7.29CPCh. 7.13 - Prob. 7.30CPCh. 7.13 - Prob. 7.31CPCh. 7 - Prob. 1MCCh. 7 - Prob. 2MCCh. 7 - Prob. 3MCCh. 7 - Prob. 4MCCh. 7 - Array bounds checking happens. a. when the program...Ch. 7 - Prob. 6MCCh. 7 - Prob. 7MCCh. 7 - Prob. 8MCCh. 7 - Prob. 9MCCh. 7 - Prob. 10MCCh. 7 - Prob. 11MCCh. 7 - To delete an item from an ArrayList object, you...Ch. 7 - Prob. 13MCCh. 7 - Prob. 14TFCh. 7 - Prob. 15TFCh. 7 - Prob. 16TFCh. 7 - Prob. 17TFCh. 7 - Prob. 18TFCh. 7 - True or False: The Java compiler does not display...Ch. 7 - Prob. 20TFCh. 7 - True or False: The first size declarator in the...Ch. 7 - Prob. 22TFCh. 7 - Prob. 23TFCh. 7 - int[] collection = new int[-20];Ch. 7 - Prob. 2FTECh. 7 - Prob. 3FTECh. 7 - Prob. 4FTECh. 7 - Prob. 5FTECh. 7 - Prob. 1AWCh. 7 - Prob. 2AWCh. 7 - Prob. 3AWCh. 7 - In a program you need to store the populations of...Ch. 7 - In a program you need to store the identification...Ch. 7 - Prob. 6AWCh. 7 - Prob. 7AWCh. 7 - Prob. 8AWCh. 7 - Prob. 9AWCh. 7 - Prob. 10AWCh. 7 - Prob. 11AWCh. 7 - Prob. 1SACh. 7 - Prob. 2SACh. 7 - Prob. 3SACh. 7 - Prob. 4SACh. 7 - Prob. 5SACh. 7 - Prob. 6SACh. 7 - Prob. 7SACh. 7 - Prob. 8SACh. 7 - Prob. 9SACh. 7 - Rainfall Class Write a RainFall class that stores...Ch. 7 - Payroll Class Write a Payroll class that uses the...Ch. 7 - Charge Account Validation Create a class with a...Ch. 7 - Charge Account Modification Modify the charge...Ch. 7 - Prob. 5PCCh. 7 - Drivers License Exam The local Drivers License...Ch. 7 - Magic 8 Ball Write a program that simulates a...Ch. 7 - Grade Book A teacher has five students who have...Ch. 7 - Grade Book Modification Modify the grade book...Ch. 7 - Average Steps Taken A Personal Fitness Tracker is...Ch. 7 - Array Operations Write a program with an array...Ch. 7 - 12.1994 Gas Prices In the student sample programs...Ch. 7 - Sorted List of 1994 Gas Prices Note: This...Ch. 7 - Name Search If you have downloaded this books...Ch. 7 - Population Data If you have downloaded this books...Ch. 7 - World Series Champions If you have downloaded this...Ch. 7 - 2D Array Operations Write a program that creates a...Ch. 7 - Prob. 18PCCh. 7 - Trivia Game In this programming challenge, you...Ch. 7 - Prob. 20PC
Knowledge Booster
Similar questions
- #include <stdio.h>#include <string.h>#define SIZE 6struct Student{char name[50];int id;float mark;};int Search1(char input[], struct Student data[]);int Search2(int input, struct Student data[]);int main() {char search_name[30];int search_id;int result1, result2;struct Student list[SIZE] = {{"Amylia", 544199, 75.4},{"Cheong", 143566, 92.3},{"Harry", 109774, 65.5},{"Krishnan", 334514, 86.7},{"Melissa", 257890, 55.4},{"Timothy",144656, 77.8}};printf("Enter Student Name: ");gets(search_name);result1 = Search1(search_name, list);//Answer for part (a)(ii) – Display the matching index of result1printf("Enter Student ID: ");scanf("%d",&search_id);result2 = Search2(search_id,list);//Answer for part (a)(iii)- Display the matching index of result2return 0;}//Answer for part (a)(i) – function definition for Search1//Answer for part (a)(iii) – function definition for Search2arrow_forwardPointers: P3: Given the following string, after you call func2, if you printed out the array, what would be printed out? string a = {"c","a","n", func2(a); "y"}; void func2(string *arr) { arr[3) - "t"; arr[2]="vi"; %3Darrow_forwardВ.width; } { t = B.type; w = { T.type = C.type; T.width = C.width; } T → B C В > int { B.type = integer; B.width 4; } В — foat { B.type = float; B.width = 8; } { C.type = t; C.width = w; } C - [ num] C1 = array(num. value, C1.type); { C.type C.width = num. value x C1. width; }arrow_forward
- T/F Suffix array can be created in O(nlogn) time.arrow_forwardint[] array = { 1, 4, 3, 6 }; What would be a proper syntax to access 3 from this array?arrow_forward#ifndef lab5ExF_h #define lab5ExF_h typedef struct point { char label[10]; double x ; // x coordinate for point in a Cartesian coordinate system double y; // y coordinate for point in a Cartesian coordinate system double z; // z coordinate for point in a Cartesian coordinate system }Point; void reverse (Point *a, int n); /* REQUIRES: Elements a[0] ... a[n-2], a[n-1] exists. * PROMISES: places the existing Point objects in array a, in reverse order. * The new a[0] value is the old a[n-1] value, the new a[1] is the * old a[n-2], etc. */ int search(const Point* struct_array, const char* target, int n); /* REQUIRES: Elements struct-array[0] ... struct_array[n-2], struct_array[n-1] * exists. target points to string to be searched for. * PROMISES: returns the index of the element in the array that contains an * instance of point with a matching label. Otherwise, if there is * no point in the array that its label matches the target-label, * it should return -1. * If there are more than…arrow_forward
- #include <iostream> using namespace std; const int ROWS = 10; const int COLS = 10; int generateRND(int MIN, int MAX) { return rand() % (MAX - MIN + 1) + MIN; } void initializeArray(int C[][COLS], int min, int max) { for (size_t i = 0; i < ROWS; i++) { for (size_t j = 0; j < COLS; j++) { C[i][j] = generateRND(min, max); } } } void swap(int A[][COLS], int B[][COLS]) { int temp; for (size_t j = 0; j < COLS; j += 2) { for (size_t j = 0 ; j< COLS; j +=) } } void printArray(int C[][COLS]) { for (size_t i = 0; i < ROWS; i++) { for (size_t j = 0; j < COLS; j++) { cout << C[i][j] << " "; } cout << endl; } } int main() { srand((unsigned)time(0)); int A[ROWS][COLS] = { 0 }; int B[ROWS][COLS] = { 0 }; const int MIN = 2; const int MAX = 50; initializeArray(A, 2, 50); } Declares two 10X10 Two-dimensional arrays A and B of type integer. Each array consists of 100 random integers between 2 and 50. 1. Swaps (exchange) the elements of A with…arrow_forward#include <iostream> using namespace std; const int ROWS = 10; const int COLS = 10; int generateRND(int MIN, int MAX) { return rand() % (MAX - MIN + 1) + MIN; } void initializeArray(int C[][COLS], int min, int max) { for (size_t i = 0; i < ROWS; i++) { for (size_t j = 0; j < COLS; j++) { C[i][j] = generateRND(min, max); } } } void swap(int A[][COLS], int B[][COLS]) { int temp; for (size_t j = 0; j < COLS; j += 2) { for (size_t j = 0 ; j< COLS; j +=) } } void printArray(int C[][COLS]) { for (size_t i = 0; i < ROWS; i++) { for (size_t j = 0; j < COLS; j++) { cout << C[i][j] << " "; } cout << endl; } } int main() { srand((unsigned)time(0)); int A[ROWS][COLS] = { 0 }; int B[ROWS][COLS] = { 0 }; const int MIN = 2; const int MAX = 50; initializeArray(A, 2, 50); } Declares two 10X10 Two-dimensional arrays A and B of type integer. Each array consists of 100 random integers between 2 and 50. Swaps (exchange) the elements of odd rows of A…arrow_forwardNonearrow_forward
- #include<iostream>using namespace std;const int rows=10;const int columns=10;int computer_board[rows][columns];int player_board[rows][columns];int x,y;void setboard(){for(int i=0;i<rows;i++){for(int j=0;j<columns;j++){computer_board[i][j]=0;player_board[i][j]=0;}}}void display_board(){cout<<"Computer's Board"<<endl;cout<<" 0 1 2 3 4 5 6 7 8 9 "<<endl;for(int i=0;i<rows;i++){for(int j=0;j<columns;j++){if(j==0){cout<<i<<" ";}cout<<computer_board[i][j]<<" "; }cout<<endl;}cout<<endl;cout<<"Your Board"<<endl;cout<<" 0 1 2 3 4 5 6 7 8 9 "<<endl;for(int i=0;i<rows;i++){for(int j=0;j<columns;j++){if(j==0){cout<<i<<" ";}cout<<player_board[i][j]<<" "; }cout<<endl;} }void place_player_ships(){for(int i=1;i<=15;i++){cout<<"Horizontal component:";cin>>x;cout<<"Vertical component:";cin>>y;if(x>=10||y>=10){cout<<"Invalid…arrow_forwardDec2Hex function : def decimal_to_hex(number): hex_map = {0: '0', 1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9', 10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'} hex_digits = [] while number > 0: hex_digits.append(hex_map[number % 16]) number //= 16 # Reverse the order of the hex digits and join them to form the final hex string hex_string = ''.join(reversed(hex_digits)) return f'0x{hex_string}' if hex_string else '0x0' Perform a Profile of your Dec2Hex function. Write a function that takes a timedate object as a parameter andcalculates the number of years from NOW to the time in the timedateobject. Add unit-testing code to your Dec2Hex exercise, and then perform aUnit test of the updated Dec2Hex code.arrow_forwardWhy Char array is preferred over String for storing password?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTNew Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning