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
Textbook Question
Chapter 7.2, Problem 7.2.5CP
Which of the following statements are valid?
- a. int i = new int(30);
- b. double d[]= new double[30];
- c. char[] r = new char(1 .. 30);
- d. int i[] = (3, 4, 3, 2);
- e. float f[]={2.3, 4.5, 6.6};
- f. char[] c =new char();
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Consider a two-by-three integer array t.
h) Write a series of statements that initializes each element of t to zero. Do not use a repetition statement.
i) Write a nested for statement that initializes each element of t to zero.
j) Write a nested for statement that inputs the values for the elements of t from the user.
k) Write a series of statements that determines and displays the smallest value in t.
l) Write a printf statement that displays the elements of the first row of t. Do not use repetition.
m) Write a statement that totals the elements of the third column of t. Do not use repetition.
n) Write a series of statements that displays the contents of t in tabular format. List the column indices as headings across the top, and list the row indices at the left of each row.
Consider the following code:
int a[5] = {1,3,5,7,9};int b = a[3]; // <--- here
Rewrite the last statement (marked “here”) without using array brackets [ ].
Group of answer choices
int b = a + 3;
int b = *(a + 3);
int b = *a + 3;
int b = *(a + 2);
You’re given an array of integers and another array of three distinct integers. The first array is guaranteed to only contain integers that are in the second array, and the second array represents a desired order for the integers in the first array. For example, a second array of [x, y, z] represents a desired order of [x, x,…,x, y, y,…,y, z, z,…,z] in the first array. Write a program that sorts the first array according to the desired order in the second array. The program should perform this in place (i.e.., it should mutate the input array), and it shouldn’t use any auxiliary space. Note that the desired order won’t necessarily be ascending or descending and that the first array won’t necessarily contain all three integers found in the second array-it might only contain one or two. Please Don't Use Chat GPT Answers
Sample input
array = [1,0,0,-1,-1,0,1,1]
order = [0,1,-1]
Sample output [0,0,0,1,1,1-1,-1]
Requirements:
1. Implement the above problem statement using C Programming.
2.…
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
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What part of the computer actually runs programs?
Starting Out with Python (4th Edition)
What are the advantages of storing classes in their own files?
Starting out with Visual C# (4th Edition)
Consider the following two relations for Millennium College: STUDENT(StudentID, StudentName, CampusAddress, GPA...
Modern Database Management (12th Edition)
When displaying a Java applet, the browser invokes the _____ to interpret the bytecode into the appropriate mac...
Web Development and Design Foundations with HTML5 (8th Edition)
Consider the following array: int [] a = new int[10]; What is the last index of a? What is the value of a.lengt...
Java: An Introduction to Problem Solving and Programming (8th 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
- Assume int[][] x = {{1, 2}, {3, 4}, {5, 6}}, what are x.length are x[0].length? 5 3 and 2 4 2 and 1 3 2 and 3 2 2 and 2 1 3 and 3arrow_forward2. Write a Java program that uses a LOOP to sum the elements of the following words array: arrayD WORD 100h, 200h, 300h, 400harrow_forwardWhat will be the contents of the a array after the following statements are executed? [8] int a[MaxSize] ={9,2,21,10,12,6,5,8,17}; int *p=&a[0],*q; q = p+MaxSize-1; ; int solution = 0; while(p<=q) { solution += *p%2 == 0? *p: 0; p++; }arrow_forward
- FOR C++, PLEASE WRITE THE CODE IN 15 MINUTES ! Write a function that finds different elements in the given two array. PLEASE WRITE YOUR CODE IN THIS METHOD. void printDifferentElements(int a[], int b[], int size) { }arrow_forwardWrite a program that will find the maximum number from 3 float type numbers.You have to use getMax which will take 3 pointer variables and return the maximum number.arrow_forwardfloat someDataValues [] = new float[30]; for (int i = 1; i < someDataValues.length - 5; i+=4) { someDataValues[i] = (float) Math.pow((i+2), 2); System.out.println((int) someDataValues[i] + " "); i++; }arrow_forward
- Filll in the below code in C program: #include <stdio.h> void main() { int pageNumbers[25], frameContents[25]; int i = 0, j = 0, k = 0; int numPages = 0, numFrames = 0, totalPageFaults = 0; int frameNumber = 0; printf("\n Page Replacement Method: FIFO"); printf("\n Enter the number of pages in the page sequence: "); // 20 scanf("%d", &numPages); printf("\n Enter the page numbers in sequence as a string: "); // 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 for (i = 0; i < numPages; i++) scanf("%d", &pageNumbers[i]); printf("\n Enter the number of frames: "); // 3 scanf("%d", &numFrames); for (i = 0; i < numFrames; i++) frameContents[i] = -1; printf("\n The Page Replacement Process is \n"); printf("\tREF STRING"); for (j = 0; j < numFrames; j++) printf("\tPAGE_FRAME_%d", j + 1); printf("\tPAGE_FAULT_NUMBER\n"); /* Find the occurance of page faults and the total number of page faults */ printf("\n\n Total number of Page Faults using FIFO: %d \n", totalPageFaults); }arrow_forwardConsider an array int a[] = {1, 2, 3}. What is the output for the following?a. cout << a+2;b. cout << *(a+2);c. cout << *a;d. cout << *a[0]; in c++arrow_forwardWrite a program that grades arithmetic quizzes as follows: (Use the below startup code for Quizzes.java and provide code as indicated) Ask the user how many questions are in the quiz. Use a for loop to load the array. Ask the user to enter the key (that is, the correct answers). There should be one answer for each question in the quiz, and each answer should be an integer. They can be entered on a single line, e.g., 34, 7, 13, 100, 8 might be the key for a 5-question quiz. You will need to store the key in an array called “key”. Ask the user to enter the student’s answers for the quiz to be graded. There needs to be one answer for each question. Note that each answer can simply be compared to the key as it is entered. If the answer is correct, add 1 to a correct answer counter. Do this in a separate for loop from the loop used to load the array. When the user has entered all of the answers to be graded, print the number correct and the percent correct. When this works, nest your for…arrow_forward
- Write a program that simulates rolling two dice. Prompt the user to enter the number of dice rolls. Use a loop to repeatedly call a method that simulates a dice roll and returns the total of the two dice to main. Keep track of the rolls in an array in main, and end the program by showing the results of the rolls.arrow_forwardExplain this C code line per line please #include <stdio.h> #include <malloc.h> void printArray(int**, int); int main() { int i = 0, j = 0, n = 5; int **arr = (int**)malloc(n * sizeof(int*)); for(int i=0;i<n;i++){ *(arr+i) = (int*)malloc(n*sizeof(int)); } for(i=0;i<n;i++){ for(int j=0;j<n;j++){ *(*(arr+i) + j) = 0; } } printArray(arr, n); for(i=0;i<n;i++){ *( *(arr + i) + i) = i+1; } printArray(arr,n); return 0; } void printArray(int ** array, int size) { int i,j; for(i = 0;i<size;i++){ for(j=0;j<size;j++){ printf("%d ", *( *(array + i) + j)); } printf("\n"); } printf("\n"); }arrow_forwardI need help please to write a program for a grocery store to calculate the total charge for customers following thisalgorithm: 1. In the main:a) ask customer for the number of items that they are purchasingb) check to see it is less than or equal to 20 itemsc) pass than number to FillPriceArray subroutine and call FillPriceArray subroutine.2. FillPriceArray subroutine:a) fill the array and accumulate the prices sub totalb) return the sub total to main.3. In the main:a) ask customer for the number of coupons (it should be the same as the number ofitems)b) pass the coupon number to FillCouponArray subroutine and call FillCouponArraysubroutine to fill the CouponArray.4. FillCouponArray subroutine:a) fills the array and accumulate the discount total*get the coupon amount:The coupon should be less than item price and coupon should not be more than $10if the coupon is more than item price or exceed $10 then you place 0 in theCouponArray for that coupon.b) return coupon sum to main5. In the…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
9.1: What is an Array? - Processing Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=NptnmWvkbTw;License: Standard Youtube License