Concept explainers
Write code that will fill the following array a with numbers typed at the keyboard:
int [][] a = new int [4][5];
Although the user will enter five numbers per line on four lines, your solution need not depend on how the input numbers are divided into lines.
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)
Additional Engineering Textbook Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Programming in C
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Database Concepts (8th Edition)
Starting Out with Python (4th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- Consider 2 integer arrays, x and y, each with size equal to 10.Initialize array x with random numbers between 1 and 100.Write code that fills array y with values such that each element of y is the corresponding valueof x multiplied by its index.arrow_forwardConsider the code snippet below: int scores[10] = { 7, 4, 10, 5, 1}; Â What code below is an equivalent way to write (scores + 1)? A) We don't know what will be output, this is out of bounds for the array B) *scores + 1 C) scores[1] D) 4 E) &(scores[1])arrow_forwardGiven an array arr of type int, along with two int variables i and j, write some code that swaps the values of arr[i] and arr[j]. Declare any additional variables as necessary.arrow_forward
- Write a hangman game that randomly generates a word andprompts the user to guess one letter at a time, as presented in the sample run.Each letter in the word is displayed as an asterisk. When the user makes a correctguess, the actual letter is then displayed. When the user finishes a word, displaythe number of misses and ask the user whether to continue to play with anotherword. Declare an array to store words, as follows:// Add any words you wish in this arrayString[] words = {"write", "that",...}; (Guess) Enter a letter in word ******* > p↵Enter(Guess) Enter a letter in word p****** > r↵Enter(Guess) Enter a letter in word pr**r** > p↵Enterp is already in the word(Guess) Enter a letter in word pr**r** > o↵Enter(Guess) Enter a letter in word pro*r** > g↵Enter(Guess) Enter a letter in word progr** > n↵Entern is not in the word(Guess) Enter a letter in word progr** > m↵Enter(Guess) Enter a letter in word progr*m > a↵EnterThe word is program. You missed 1 timeDo…arrow_forwardCan you make the array be randomly genorated instead of already named values, and ask the user to enter the number of numbers that will be genorated in the array. Everything else can stay the same. '''def binary_search(arr, x): low = 0high = len(arr) - 1mid = 0while low <= high: mid = (high + low) // 2if arr[mid] < x: low = mid + 1elif arr[mid] > x: high = mid - 1else: return mid return -1arr = [ 2, 3, 4, 10, 40 ] print("The array is [ 2, 3, 4, 10, 40 ]")x = int(input("Enter which value do you seek to find from the array above? "))while not (x==2 or x==3 or x==4 or x == 10 or x == 40):print("Option isn't in the array.")x = int(input("Please input a valid number to search "))result = binary_search(arr, x) print("Searching for", x) if result != -1: print("Element is present at index", str(result))arrow_forwardwrite a code that will fill the array a int a[4][5]; with numbers typed at the keyboardarrow_forward
- Write 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_forwardc++ Write a program that declares an array of 15 integers and reads the values from the user. Make sure that the user doesn’t enter a value greater than 10 (if the user enters a value not in the allowed range, discard that value and read another to put into the array). Now tell the number that occur maximum number of times in the array. For example for the following 7 has maximum occurrence. 4,7,3,3,2,7,1,5,7,9,9,9,7,8,10 Use both linear and binary search.arrow_forwardWrite a Java program tat prompts user for a list of integers with 0 as the last value.Save the values in an array. Assume there can be maximum 100 values. Theprogram should have the following methods:- A method that takes the array as parameter and updates each value in thearray to the square of the value.- Another method that takes the original and modified arrays as parametersand displays the original and the squared values.arrow_forward
- Instrument shellsort to print the number of compares divided by the array sizefor each increment. Write a test client that tests the hypothesis that this number is asmall constant, by sorting arrays of random Double values, using array sizes that areincreasing powers of 10, starting at 100arrow_forwardConsider 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);arrow_forwardWrite a program that declares an array of size 10.Read 10 integer from user and store them in the array then prints them out in reverse order.arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT