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 7.2, Problem 10STQ
Give the definition of a static method called showArray that has an array of base type char as a single parameter and that writes one line of text to the screen consisting of the characters in the array argument written in order.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a JAVA program
Write a function inside ProblemSolution class whose return type is void, accepts an array and the length of the array as input parameters. The function should call a static method display of MyArray class by passing an array and length value.
Input 5 1 5 8 2 0
Where,
First line of input represents the size of an array.
Second line represents array elements.
Output 1 5 8 2 0
Assume that,
N is an integer within the range [0 to 10000].
Array elements are integers within the range [-2147483648 to 2147483647].
2. write two method called findIndex and findLastIndex that search for a number in an array. they
should take an int array and an int as parameters. findIndex should return the index of the first
instance of the number in the array. findLastIndex should return the index of the last instance of
the number in the array. They both should return -1 if the number is not found. Do not use any
library methods.
Sample code
int a[]
int x = findIndex(a,50);
Sample output
{10,50,30, 40,50};
1
System.out.println(x);
int a[]
int x = findLastIndex (a,50);
System.out.println(x);
int a[] = {10,50,30,40,50};
int x = findIndex(a,70);
{10,50,30,40,50};
4
-1
System.out.println(x);
Java
Chapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - Consider the following array: int [] a = new...Ch. 7.1 - What is wrong with the following code to...Ch. 7.1 - Write a complete Java program that reads 20 values...Ch. 7.2 - Write some Java code that will declare an array...Ch. 7.2 - Rewrite the method displayResults of the program...Ch. 7.2 - What output will be produced by the following...Ch. 7.2 - Give the definition of a static method called...
Ch. 7.2 - Give the definition of a static method called...Ch. 7.2 - Prob. 12STQCh. 7.2 - The following method compiles and executes but...Ch. 7.2 - Suppose that we add the following method to the...Ch. 7.3 - Prob. 15STQCh. 7.3 - Replace the last loop in Listing 7.8 with a loop...Ch. 7.3 - Suppose a is an array of values of type double....Ch. 7.3 - Suppose a is an array of values of type double...Ch. 7.3 - Prob. 19STQCh. 7.3 - Consider the partially filled array a from...Ch. 7.3 - Repeat the previous question, but this time assume...Ch. 7.3 - Write an accessor method getEntryArray for the...Ch. 7.4 - Prob. 23STQCh. 7.4 - Write the invocation of the method selectionSort...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - Consider an array b of int values in which a value...Ch. 7.5 - What output is produced by the following code?...Ch. 7.5 - Revise the method showTable in Listing 7.13 so...Ch. 7.5 - Write code that will fill the following array a...Ch. 7.5 - Write a void method called display such that the...Ch. 7.6 - Prob. 33STQCh. 7 - Write a program in a class NumberAboveAverage that...Ch. 7 - Write a program in a class CountFamiles that...Ch. 7 - Write a program in a class CountPoor that counts...Ch. 7 - Write a program in a class FlowerCounter that...Ch. 7 - Write a program in a class characterFrequency that...Ch. 7 - Create a class Ledger that will record the sales...Ch. 7 - Define the following methods for the class Ledger,...Ch. 7 - Write a static method isStrictlyIncreasing (double...Ch. 7 - Write a static method removeDuplicates(Character[]...Ch. 7 - Write a static method remove {int v, int [] in}...Ch. 7 - Suppose that we are selling boxes of candy for a...Ch. 7 - Create a class polynomial that is used to evaluate...Ch. 7 - Write a method beyond LastEntry (position) for the...Ch. 7 - Revise the class OneWayNoRepeatsList, as given in...Ch. 7 - Write a static method for selection sort that will...Ch. 7 - Overload the method selectionSort in Listing 7.10...Ch. 7 - Revise the method selectionSort that appears in...Ch. 7 - Prob. 18ECh. 7 - Write a sequential search of an array of integers,...Ch. 7 - Write a static method findFigure (picture,...Ch. 7 - Write a static method blur (double [] [] picture)...Ch. 7 - Write a program that reads integers, one per line,...Ch. 7 - The following code creates a small phone book. An...Ch. 7 - Write the method rotateRight that takes an array...Ch. 7 - The following code creates a ragged 2D array. The...Ch. 7 - Write a program that will read a line of text that...Ch. 7 - Prob. 2PPCh. 7 - Add a method bubbleSort to the class ArraySorter,...Ch. 7 - Add a method insertionSort to the class...Ch. 7 - The class TimeBook in Listing 7.14 is not really...Ch. 7 - Define a class called TicTacToe. An object of type...Ch. 7 - Repeat Programming Project 10 from Chapter 5 but...Ch. 7 - Prob. 8PPCh. 7 - Write a GUI application that displays a picture of...Ch. 7 - ELIZA was a program written in 1966 that parodied...Ch. 7 - Prob. 11PPCh. 7 - Create a GUI application that draws the following...Ch. 7 - Practice Program 2 used two arrays to implement a...Ch. 7 - Practice Program 5.4 asked you to define Trivia...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Car Class Write a class named Car that has the following data attributes: _ _year_model (for the car's year mo...
Starting Out with Python (4th Edition)
Speedcoding was invented to overcome two significant shortcomings of the computer hardware of the early 1950s. ...
Concepts Of Programming Languages
Describe the difference between pretest loops and posttest loops.
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Write a definition for a structure type for records consisting of a persons wage rate, accrued vacation (which ...
Problem Solving with C++ (10th Edition)
Consider the adage Never ask a question for which you do not want the answer. a. Is following that adage ethica...
Experiencing MIS
Convert the following for loop to a while loop: for (int x = 50; x 0; x--) { System.out.println(x + seconds t...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
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 method that takes two arrays as parameters. It should return a new array where each position has the sum of the two corresponding positions in the two incoming arrays. The returned array should be as long as the longer of the two passed in arrays.arrow_forwardWrite a program C# named Averages that includes a method named Average that accepts any number of numeric parameters, displays them, and displays their average. For example, if 7 and 4 were passed to the method, the output would be: 7 4 -- Average is 5.5 Test your function in your Main(). Tests will be run against Average() to determine that it works correctly when passed one, two, or three numbers, or an array of numbers. using static System.Console; public class Averages { public static void Main() { // Write your main here } }arrow_forwardJava Problem: Implementing a method to print a cell's neighbors on a 2D array. The method's header is provided. The main method (do not alter it)w ill read N numbers to create the 2D array and it will call the method for you. Do not go out of the bounds of the 2D array. I have attached what it should look like with the following input: 4 4 1 2 3 4 7 8 9 10 13 14 15 16 19 20 21 22 2 2 Code I have so far: import java.util.Arrays;import java.util.Scanner;public class Problem3 {public static void printNeighbours(int[][] data, int row, int col){}public static void main(String[] args) {Scanner kb = new Scanner(System.in);int[][] data = new int[kb.nextInt()][kb.nextInt()];for (int i = 0; i < data.length; i++) {for (int j = 0; j < data[0].length; j++) {data[i][j] = kb.nextInt();}}System.out.println("The 2D Array:");for (int[] cols : data) {System.out.println(Arrays.toString(cols));}int row = kb.nextInt();int col = kb.nextInt();System.out.printf("The centre point is: %d %d…arrow_forward
- Language: Java Write a class encapsulating the concept of daily temperatures for a week with a single dimensional array of temperatures. Write the following methods: A constructor accepting an array of seven temperatures as a parameter. Accessor, mutator, toString() and equals() methods A method returning how many temperatures were below freezing. A method returning an array of temperatures above 100 degrees. A method returning the largest change in temperature between any two consecutive days. A method returning an array of daily temperatures, sorted in descending order (do not use a built-in Java class, modify one of the sorting algorithms in the textbook). Write a client class to test all the methods in your class.arrow_forwardJava languagearrow_forwardQUESTION 2 Write a Java program to input a single dimensional integer array of size 8. Pass the array to a method named countBigNumbers that return integer. In this method, count the array elements that are bigger than 50 and place them in another array. Display the returned count in main method. Display the two arrays by invoking a method named displayArray. 2 Sample inputs and their outputs are shown below: Input 8 numbers: 5 60 8 99 1 100 7 51 Count of numbers bigger than 50 is 4 Array1 is 5 60 100 51 66 Array2 is 60 99 100 51 Input 8 numbers: 80 19 91 150 37 23 50 49 Count of numbers bigger than 50 is 3 Arrayl is 80 19 91 100 37 23 50 49 Array2 is 80 91 100arrow_forward
- Need help with this question Write a Java program that asks the user to enter an array of integers in the main method. The program should prompt the user for the number of elements in the array and then the elements of the array. The program should then call a method named minGap that accepts the array entered by the user as a parameter and returns the minimum 'gap' between adjacent values in the array. The main method should then print the value returned by the method. The gap between two adjacent values in an array is defined as the difference in value between the first element and the second element. For example, suppose the user entered the following array of integers {1, 3, 6, 5, 12} The first gap is 2 (3 - 1), the second gap is 3 (6 - 3), the third gap is 1 (6 - 5) and the fourth gap is 5 (12 - 6). Thus, the call of minGap(array) should return 1 because that is the smallest gap in the array. If you are passed an array with fewer than 2 elements, you…arrow_forwardWrite a program that creates a 2-D array initialized with test data . Use any primitive type of data EXCEPT int (Integer). The program should have all methods in the problem. getTotal - This method should accept a two-dimensional array as its argument and return the total of all the values in the array. getAverage - This method should accept a two-dimensional array as its argument and return the average of all the values in the array. getRowTotal. - This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the total of the values in the specified row. getColumnTotal - This method should accept a two-dimensional array as its First argument and an integer as its second argument. The second argument should be the subscript of a column in the array. The method should return the total of the values in the specified column.…arrow_forwardWrite a method with header static void DisplayIntArray(int[] numbers). The first argument is an array of ints. There is no return value. This method displays all the elements of the argument on a single line. Each item will occupy three columns.Call this method from main with a suitable argument. Write a method with header static int[] GenerateRandomIntArray(int numberOfItems, int largestValue). The first argument is an int indicating the number of elements that will be present in the return array. The second argument is an int representing the largest item in the array. The returned value is an array of integers. This method does the following: Declare and initialized a variable of type Random (Random generator = new Random();) Declare an array of type int (you may call it result) Allocate storage for the correct number of items Using your favorite looping statement, assign a random integer to each element of the array (result[i] = generator.Next(largestValue);) In your…arrow_forward
- Write a C# program named Averages that includes a method named Average that accepts any number of numeric parameters, displays them, and displays their average. For example, if 7 and 4 were passed to the method, the output would be: 7 4 -- Average is 5.5 Test your function in your Main(). Tests will be run against Average() to determine that it works correctly when passed one, two, or three numbers, or an array of numbers.arrow_forwardCan help in javaWrite a program that mimics the roll of a dice by several players, each with a maximum of 5 attempts. Save the results in the 2D results array. The program should display an array with the results and the number of the experience in which the player threw 6, or the message that the player did not throw 6.arrow_forwardQuestion: 1. Write a method that has an int parameters. Creates an array of integers of that size. Reads in values for the array from the user. Returns the newly created array. 2 Write a method that given an array of integers.returns the index of the smallest integer.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
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