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
Textbook Question
Chapter 11.2, Problem 14STQ
If a value in an array of base type int occurs twice—for example, both b[0] and b[5] are 7—and you sort the array by using the method MergeSort.sort, will there be one or two copies of the repeated value after the array is sorted?
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Create a program that can find the mode of a sorted dynamic array and print it. If there is more than one mode found print them in ascending order.
Example of array: {20, 30, 30, 50, 70 , 80, 80, 90, 100}.
no sorting necessary
Create a 1D integer array of size 17. Fill each index with a random value ranging from 1 to 359 inclusive. You will then design and implement the Random Sort algorithm using the following methods:
Create a method called check_if_sorted (). It should take in a 1D integer array and return a boolean value. It should return TRUE if the array is sorted in nondescending order, and FALSE otherwise. Hint: If you compare elements in the array and a pair is in the wrong order, that would mean the array is not in non-descending order.
Create a method called shuffleArray (). It should take in a 1D integer array and return a 1D integer array. Shuffle the array so that the values are in random different indexes, and return altered array. Hint: There are many approaches to solve this problem – making a second array in the shuffleArray () method might be part of the answer.
Create a method called PrintArray (). It should take in a 1D integer array and return nothing. Simply print the current values…
in java
Integer numElements is read from input, representing the number of integers to be read next. Then, the remaining integers are read and stored into array valuesArray. For each element in valuesArray that is divisible by 9, assign the element with the element's current value plus 1.
Ex: If the input is:
3 81 99 30
then the output is:
Original values: 81 99 30 New values: 82 100 30
Note: (x % 9 == 0) returns true if x is divisible by 9.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
for (i=0; i<valuesArray.length; ++i) {
valuesArray[i] =scnr.nextInt();
}
System.out.print("Original values: ");
for (i=0; i<valuesArray.length; ++i) {
System.out.print(valuesArray[i] +" ");
}
System.out.println();
/* Your code goes here */
System.out.print("New values: ");
for (i=0; i<valuesArray.length; ++i) {
System.out.print(valuesArray[i] +" ");
}
System.out.println();
}
}
Chapter 11 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 11.1 - What output will be produced by the following...Ch. 11.1 - What is the output produced by the following code?Ch. 11.1 - Write a recursive definition for the following...Ch. 11.1 - What is the output of the following code? public...Ch. 11.1 - Prob. 5STQCh. 11.1 - Complete the definition of the following method....Ch. 11.2 - Revise the method getCount in Listing 11.5 so that...Ch. 11.2 - Prob. 8STQCh. 11.2 - Prob. 9STQCh. 11.2 - Suppose you want me class ArraySearcher to work...
Ch. 11.2 - What Java statement will sort the following array,...Ch. 11.2 - How would you change the class MergeSort so that...Ch. 11.2 - How would you change the class MergeSort so that...Ch. 11.2 - If a value in an array of base type int occurs...Ch. 11 - What output will be produced by the following...Ch. 11 - What output will be produced by the following...Ch. 11 - Write a recursive method that will compute the...Ch. 11 - Write a recursive method that will compute the sum...Ch. 11 - Complete a recursive definition of the following...Ch. 11 - Write a recursive method that will compute the sum...Ch. 11 - Write a recursive method that will find and return...Ch. 11 - Prob. 8ECh. 11 - Write a recursive method that will compute...Ch. 11 - Suppose we want to compute the amount of money in...Ch. 11 - Prob. 11ECh. 11 - Write a recursive method that will count the...Ch. 11 - Write a recursive method that will remove all the...Ch. 11 - Write a recursive method that will duplicate each...Ch. 11 - Write a recursive method that will reverse the...Ch. 11 - Write a static recursive method that returns the...Ch. 11 - Write a static recursive method that returns the...Ch. 11 - One of the most common examples of recursion is an...Ch. 11 - A common example of a recursive formula is one to...Ch. 11 - A palindrome is a string that reads the same...Ch. 11 - A geometric progression is defined as the product...Ch. 11 - The Fibonacci sequence occurs frequently in nature...Ch. 11 - Prob. 4PPCh. 11 - Once upon a time in a kingdom far away, the king...Ch. 11 - There are n people in a room, where n is an...Ch. 11 - Prob. 7PPCh. 11 - Prob. 10PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Modify Program 7.14 so that the user can convert any number of integers. Make provision for the program to term...
Programming in C
If you are writing a function that accepts an argument and you want to make sure the function cannot change the...
Starting Out with C++: Early Objects
What is a source program?
Absolute Java (6th Edition)
When Option Strict is set to ______ only widening conversions are permitted.
Starting Out With Visual Basic (7th Edition)
Create an object of class Student. You will notice that this time you are prompted not only for a name of the i...
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
A __________ property can be set to one of two possible values: True or False. a. Boolean b. Logical c. Binary ...
Starting out with Visual C# (4th 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
- int[] cars = {1,2,3,4,5}; for (int i=0; iarrow_forwardGiven a sorted array of n integers that has been rotated an unknownnumber of times, write code to find an element in the array. You may assume that the array wasoriginally sorted in increasing order.EXAMPLElnput:find5in{15, 16, 19, 20, 25, 1, 3, 4, 5, 7, 10, 14}Output: 8 (the index of 5 in the array)arrow_forwardReturn the maximum value from the provided integer array. You may assume that all values in the array will be non-negative. getMax([1]) → 1getMax([0, 3, 2, 12, 4]) → 12getMax([15, 3, 1, 7, 2]) → 15 public int getMax(int[] nums) { Write your code in here using this outline.}arrow_forwardWrite a computer program for searching an array consist of following numbers. [ 12 32 73 95 23 45 26 48 83 24 56 19 23 28 45 ] User enters a number for searching. If an array does not contain the number to the last row of the array. If the number is still exists, script outputs the text message " The number is already exists".arrow_forwardSales.java contains a Java program that prompts for and reads in the sales for each of 5 salespeople in a company. Now modify the program as follows: Declare an array called sales to save the sales of 5 salespeople. Complete the header of the first for loop. This loop initializes the array. Complete the header of the second for loop. This loop computes the total of array elements. Add code to compute and print the average sale. Add another loop to print the id of each salesperson and the number of their sales. The salespeople are objecting to having an id of 0—no one wants that designation. Modify your program so that the IDs run from 1-5 instead of 0-4. // *************************************************************** // Sales.java // // Reads in and stores sales for each of 5 salespeople. Displays // sales entered by salesperson id and total sales for all salespeople. // // *************************************************************** import java.util.Scanner;…arrow_forwardWe have an array variable ‘var’ int var[4] = {25,20,30,40}; Find the memory address of the first element of in the array: var[0]arrow_forwardC programming languagearrow_forwardIf an array is given, identify the next bigger element for each element in the array, if one exists. If the element is not accessible, print the element itself. The next bigger element y in the array for an element x is the first element that is greater than x and appears on its right side. The element itself is the next bigger member of the array's rightmost element. Example: Given A = [ 6 8 4 3 9] the next greater element listB = [8 9 9 9 9]. use python to code If an array is given, identify the next bigger element for each element in the array, if one exists. If the element is not accessible, print the element itself. The next bigger element y in the array for an element x is the first element that is greater than x and appears on its right side. The element itself is the next bigger member of the array's rightmost element. Example: Given A = [ 6 8 4 3 9] the next greater element listB = [8 9 9 9 9]. use python to code If an array is given, identify the next bigger element for each…arrow_forwardIf an array is given, identify the next bigger element for each element in the array, if one exists. If the element is not accessible, print the element itself. The next bigger element y in the array for an element x is the first element that is greater than x and appears on its right side. The element itself is the next bigger member of the array's rightmost element. Example: Given A = [ 6 8 4 3 9] the next greater element listB = [8 9 9 9 9]. use python to codearrow_forwardAn array is special if every even index contains an even number and every odd index contains an odd number. Create a function that returns true if an array is special, and false otherwise. Examples isSpecialArray([2, 7, 4, 9, 6, 1, 6, 3]) → true // Even indices: [2, 4, 6, 6]; Odd indices: [7, 9, 1, 3] isSpecialArray([2, 7, 9, 1, 6, 1, 6, 3]) → false // Index 2 has an odd number 9. isSpecialArray ([2, 7, 8, 8, 6, 1, 6, 3]) → false // Index 3 has an even number 8.arrow_forwardWrite 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_forwardin Pseudo code Create an array of size 10 and name RandArray populate the RandArray with random integer from 1 to 20. Every element in the RandArray must be changed as follows: If the value of the element is less than the array index, the element must be replaced with the index plus 10. If the value of the element is equal to the index, the element must be doubled. If the value of the element is greater than the index, the element must be replaced by the index squared. Print the original number and the changed number of the RandArray .arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License