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 8.2, Problem 8.2.4CP
Which of the following statements are valid?
int [] [] r = new int[2];
int [] x = new int[];
int [] [] y = new int[3] [];
int [] [] z = {{1, 2}};
int [] [] m = {{1, 2}, {2, 3}};
int [] [] n = {{1, 2}, {2, 3},} ;
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a Java program named RandomNumbers that creates a single-dimensional array of int of size 20 and initialize its elements with 20 random integer numbers (their range must be between 1 and 100 inclusive.
a) Write statements in your program to display the array elements, and how many odd and even numbers are there in the array. For example, if the random numbers were stored in the array are:83 48 89 66 40 94 31 31 12 45 45 87 10 24 78 2 28 31 52 46Then the program should display:The random numbers are:83 48 89 66 40 94 31 31 12 45 45 87 10 24 78 2 28 31 52 46There are 8 odd numbersThere are 12 even numbersb) An element in the array is a peak (max or min) if the elements before and after that element are greater than the element itself (min) or the elements before and after that element are less than the element (max). Write a method in your program called displayPeaks that will take a single-dimensional array as parameter and display all peak elements of that array…
Write a Java program named RandomNumbers that creates a single-dimensional array of int of size 20 and initialize its elements with 20 random integer numbers (their range must be between 1 and 100 inclusive.
a) Write statements in your program to display the array elements, and how many odd and even numbers are there in the array.
For example, if the random numbers were stored in the array are:
83 48 89 66 40 94 31 31 12 45 45 87 10 24 78 2 28 31 52 46
Then the program should display:
The random numbers are:
83 48 89 66 40 94 31 31 12 45 45 87 10 24 78 2 28 31 52 46
There are 8 odd numbers
There are 12 even numbers
javaprogram that uses an array with ten random integers to prints four lines of output, containing all even elements, every element at a even index, elements in reverse order, only first and last element
thank you!!
Chapter 8 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 8.2 - Declare an array reference variable for a...Ch. 8.2 - Prob. 8.2.2CPCh. 8.2 - What is the output of the following code? int[] []...Ch. 8.2 - Which of the following statements are valid? int...Ch. 8.3 - Show the output of the following code: int[][]...Ch. 8.3 - Show the output of the following code: int[][]...Ch. 8.4 - Show the output of the following code: public...Ch. 8.5 - Prob. 8.5.1CPCh. 8.6 - What happens if the input has only one point?Ch. 8.7 - What happens if the code in line 51 in Listing 8.4...
Ch. 8.8 - Declare an array variable for a three-dimensional...Ch. 8.8 - Assume char[][][] x =new char[12][5][2], how many...Ch. 8.8 - Show the output of the following code: int[][][]...Ch. 8 - (Sum elements column by column) Write a method...Ch. 8 - (Sum the major diagonal in a matrix) Write a...Ch. 8 - (Sort students on grades) Rewrite Listing 8.2,...Ch. 8 - (Compute the weekly hours for each employee)...Ch. 8 - (Algebra: add two matrices) Write a method to add...Ch. 8 - (Algebra: multiply two matrices) Write a method to...Ch. 8 - (Points nearest to each other) Listing 8.3 gives a...Ch. 8 - (All closest pairs of points) Revise Listing 8.3,...Ch. 8 - Prob. 8.9PECh. 8 - (Largest row and column) Write a program that...Ch. 8 - (Game: nine heads and tails) Nine coins are placed...Ch. 8 - (Financial application: compute tax) Rewrite...Ch. 8 - (Locate the largest element) Write the following...Ch. 8 - (Explore matrix) Write a program that prompts the...Ch. 8 - (Geometry: same line ?) Programming Exercise 6.39...Ch. 8 - (Sort two-dimensional array) Write a method to...Ch. 8 - (Financial tsunami) Banks lend money to each...Ch. 8 - (Shuffle rows) Write a method that shuffles the...Ch. 8 - (Pattern recognition: four consecutive equal...Ch. 8 - Prob. 8.20PECh. 8 - (Central city) Given a set of cities, the central...Ch. 8 - (Even number of 1s) Write a program that generates...Ch. 8 - (Game: find the flipped cell) Suppose you are...Ch. 8 - (Check Sudoku solution) Listing 8.4 checks whether...Ch. 8 - Prob. 8.25PECh. 8 - (Row sorting) Implement the following method to...Ch. 8 - (Column sorting) Implement the following method to...Ch. 8 - (Strictly identical arrays) The two-dimensional...Ch. 8 - (Identical arrays) The two-dimensional arrays m1...Ch. 8 - (Algebra: solve linear equations) Write a method...Ch. 8 - (Geometry: intersecting point) Write a method that...Ch. 8 - (Geometry: area of a triangle) Write a method that...Ch. 8 - (Geometry: polygon subareas) A convex four-vertex...Ch. 8 - (Geometry: rightmost lowest point) In...Ch. 8 - (Largest block) Given a square matrix with the...Ch. 8 - (Latin square) A Latin square is an n-by-n array...Ch. 8 - (Guess the capitals) Write a program that...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
The decimal number 17 is equal to the binary number 10010 11000 10001 01001
Digital Fundamentals (11th Edition)
Write some Java code to create an output stream of type ObjectOutputStream that is named to File and is connect...
Java: An Introduction to Problem Solving and Programming (7th Edition)
Explain the problems that denormalized tables may have for insert, update, and delete actions.
Database Concepts (8th Edition)
What is the output of the following program? #include iostream using namespace std; void fund1(double, int); //...
Starting Out with C++: Early Objects (9th Edition)
What are the advantages in implementing a language with a pure interpreter?
Concepts of Programming Languages (11th Edition)
What is an object? What is a control?
Starting Out With Visual Basic (7th 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
- write a program in java that creates an array of size 30 and type int, allows user to enter the values of all 30 elements and finds the sum of all 30 elementsarrow_forwardvoid radixSort(int arr[], int n) { intm=getMax(arr, n); for (intexp=1; m/exp>0; exp*=10) countSort(arr, n, exp); } void printData(int arr[], int start, int len) { if( start>=len ) return( 0 ); printf("%d\n", arr[start]); printData(arr, start+1, len); } int main() { intarr[]= {8, 9, 3, 4, 7, 2, 5, 6, 1}; intn=sizeof(arr) /sizeof(arr[0]); radixSort(arr, n); printData(arr, 0, n); return0; } In MIPSarrow_forwardThis program is meant to be written in java write a program that stores 20 random integers between 1 and 100 (inclusive) in an array of integers. you have to print out:the list of integersThe list of integers backwardsHow many integers are below 50How many integers are above or equal to 50How many integers are evenarrow_forward
- Hello. I need assistance writing a method to merge two arrays and then print the new merged array. I have written the following: import java.util.ArrayList; public class HW1{ public static void main(String[] args){ArrayList<Integer> arr1 = new ArrayList<Integer>(); arr1.add(1);arr1.add(4);arr1.add(9);arr1.add(16);arr1.add(21);arr1.add(33);arr1.add(41);arr1.add(52);System.out.println("Array 1" + arr1);ArrayList<Integer> arr2 = new ArrayList<Integer>();arr2.add(4);arr2.add(7);arr2.add(9);arr2.add(9);arr2.add(20);arr2.add(25);arr2.add(27);System.out.println("Array 2" + arr2);} I need to write a method that merges the two arrays and sorts the new array from lowest number to highest. Then I need to print the new array. The output should be the following: 1 4 4 7 9 9 9 16 20 21 33 41 52 Thank you.arrow_forward(Java) question 2 Write your answer in bold Fill in the missing parts of the binarySearch method below: public static int binarySearch(double array[], double value) { int low = 0; int high = array.length - 1; while (low <= high) { int mid = (low + high)/2; if (array[ mid ] == value) { return ; } else if (value < array [ mid ]) { high = ; } else { low = mid + 1; } } //end of while loop return -1; }arrow_forward(in Java language) Write a method that is inspired by a photo app that does the following. Ask the user to enter a size of array between 2 to 10. Based on the size entered, write a loop which asks the user to fill values into an integer array. Print the array contents using Arrays.toString(). For this integer array, write a logic that returns true if there exists a place to split the array such that the sum of the numbers on one side is equal to the sum of the numbers on the other. Otherwise return false. Examples: If the array is {1, 1, 1, 2, 1} then return true. If the array is {2, 1, 1, 2, 1} then return false If the array is {10, 10} then return true.arrow_forward
- Write the output of the following Java program segment.Write only the output, nothing else! ArrayList<Integer> a2 = new ArrayList<Integer>();for (int j = 20; j <= 40; j += 4){a2.add(j);}System.out.println(a2.get(4) - a2.get(2));arrow_forward(IN JAVA) Write a method which does the following: Ask the user to enter a size of array between 2 to 10. Based on the size entered, write a loop which asks the user to fill values into an integer array. Print the array contents using Arrays.toString(). For this integer array, write a logic that returns true if there exists a place to split the array such that the sum of the numbers on one side is equal to the sum of the numbers on the other. Otherwise return false. Examples: If the array is {1, 1, 1, 2, 1} then return true. If the array is {2, 1, 1, 2, 1} then return false If the array is {10, 10} then return true.arrow_forwardWrite a program that first reads an integer for the array size, then reads numbers intothe array, and finally outputs how many numbers have values that are greater than theaverage. For practice reasons, try not to use the index notation of arrays (e.g. myarray[i])at all. Use pointers instead.arrow_forward
- FOR JAVA Write a method that takes a one dimensional integer array and an integer, and returns the index of the integer in the array. If the integer is not in the array, your program must return -1. If there are multiple occurrences of that number, your program must return the smallest index.arrow_forwardRequirements: Use Java Programming only. Show screenshots of your work. 6. Write method public static int linearSearch(int [] arr, ine key) which returns the largest index such that arr[index] matches the key. If there is match, returns -1. 7. Write method public static double average(int [] arr) which returns the average of all elements in given array arr. Assume that arr has length at least 1. 8. Write method public void crazyPrint(String sentence, int n) which print out the given sentence n times. Assume n is positive integer.arrow_forwardGiven two arrays that are full of integers, recursively merge these two arrays into one large array. The large array should have items from the first array in even indices (0,2,4 ...) and items from the second array in odd indices (1,3,5 ...). Only use recursion to complete this task. You cannot change the method header. public void mergeArrays(int[] arrayOne, int[] arrayTwo, int[] mergedArray){ // Your code here }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