Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 7.5, Problem 30STQ
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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Problem Description - JAVA PROGRAMMING
Use a Two-dimensional (3x3) array to solve the following problem:
Write an application that inputs nine numbers, each of which is between 1 and 10, inclusive.
Display the array after the user inputs each value.
Rotate/flip the array by changing places. Make the rows columns and vice versa. You have to move the elements to their new locations.
Remember to validate the input and display an error message if the user inputs invalid data.
Documentation and the screenshot(s) of the results.
Example:
1 2 3
4 5 6
7 8 9
the result will be :
1 4 7
2 5 8
3 6 9
EX15: write
a program
that
return (1)
when
input number
odd
return (2) when input number is even
5/7
EX16: write a program that separate the content of a
input array (a)
into
two
arrays;
(x) : contain
the
6/7
numbers with odd index and other array (y) contain
numbers with even index .
EX17:let you have array A[20], write a program that
read the array and swap the content of odd index with
7/7
the content of even index .
A positive integer greater than 1 is said to be prime if it has no divisors other than 1 and itself. Write a program that asks the user to input an integer greater than 1, then display all of the prime numbers that less than or equal to the number entered. The program should work as follows:
• Once the user has entered a number, the program should display an array with all of the integers from 2 up through the value entered.
• The program should then use a loop to step through the array. The loop should pass each element to a method that displays the element whether it is prime number.
Your result should look like, for example:
Enter an integer greater than 1: 9
2, 3, 4, 5, 6, 7, 8, 9
2 is prime
3 is prime
4 is not prime
5 is prime
6 is not prime
7 is prime
8 is not prime
9 is not prime
Using java programming
Chapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (8th 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.6 - Prob. 34STQCh. 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 - A palindrome is a word or phrase that reads the...Ch. 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
(Modified Compound-Interest Program) Modify the application in Fig. 5.6 to use only integers to calculate the c...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
What is denormalization?
Database Concepts (8th Edition)
What is pseudocode?
Starting Out with C++: Early Objects (9th Edition)
In Exercises 41 through 46, identify the errors.
Introduction To Programming Using Visual Basic (11th Edition)
Which loop should you use when you know the number of required iterations?
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
The thin-walled cylinder can be supported in one of two ways as shown. Determine the state of stress in the wal...
Mechanics of Materials (10th 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
- 4. Given an array of ints, return the number of times that two 6's are next to each other in the array.int n[] = {2, 6, 71, 6, 6, 6, 34, 6, 6, 89}; C++arrow_forwardProblem2 Write a program that display the position of a given element in an array. You should print the index (i.e. the position) of the element. If the element appears more than one time than you should print all its positions. The size of the array should be entered by the user. If the element does not occur then you should display element not found. Sample1: Enter the size of the array: 5 Enter an array of size 5: 44 5 13 44 67 Enter the element to find: 44 44 is found at position 44 is found at position 44 occurs 2 time(s) Sample2: Enter the size of the array: 4 Enter an array of size 4: 12 150 17 20 Enter the element: 18 18 is not foundarrow_forwardQ5: Your program allows users to enter array of n integers, where n is entered by the user (n should be kept as a small value, in this case, n <= 10). Your program should then print the sum of squared of each even integer. Hint: It is possible to use int* array = (int*)malloc(sizeof(int)*n) to create a dynamic array Below is an example: 1 2 4 1 3 OUTPUT: 20 Press any key to continuearrow_forward
- JAVA PROGRAM: Monkey Business A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a two-dimensional 3 × 5 array, where each row represents a different monkey and each column represents a different day of the week. The program should first have the user input the data for each monkey, or use constant values rather than asking user for input. Then it should create a report that includes the following information: Display 3X5 array first. Average amount of food eaten per day by the whole family of The least amount of food eaten during the week by any one The greatest amount of food eaten during the week by any one Input Validation: Do not accept negative numbers for pounds of food eaten.arrow_forwardLab Activity for the students: Exercise 5: Write a program that asks the user to input 8 numbers and save them in a 2D array with 4 rows and 2 columns. The program finds the sum of all elements and prints the array in reverse order. (1 Mark ) Example : If the inputs are 12, 7, 23, 86, 40, 64, 97, 55. Then, the program will print: 55 97 64 40 86 23 7 12 Sum = 384arrow_forwardGiven the following array, int num[5]={3,6,9,12,15}, what will be the value of score for the given statement, score=num[3];arrow_forward
- Part 1: Randomizing an Array In this problem you will write a program that will randomize the elements of an array created by the user. 1. Prompt the user to enter an integer, then asks the user to enter that many values. Store these values in an array and print the array. Then re-shuffle the array elements so randomly. Do not just randomize the order in which they are printed; actually change the way they are stored in the array. Do not create a second array; just rearrange the elements within the array you have. (Hint: Swap elements that need to change places.) When the elements have been randomized, print the array again. 2. Create another version of your program that applies the following modification to the randomization process: elements that have been already swapped should not be swapped again. Example: if element 1 was swapped with element 10, when the 10 th element is reached it should not be swapped again. Yet if the 2 nd element is reached it can be swapped with the 10o the…arrow_forwardGiven the following array declaration:int array[30];Note that you DON’T know the values in the array.Use a for loop to increment the contents of the even indexed (0, 2, 4, 6, 8 …) elements by the value of 4.Output the first component of array.Set of the value of the fourth component of array to 7 multiplied by the value of the 30th component of array plus 8.arrow_forwardgvwsrearrow_forward
- Arrays Write three statements to print the first three elements of array runTimes. Follow each statement with a newline. Ex: If runTime = {800, 775, 790, 805, 808}, print:800 775 790Note: These activities will test the code with different test values. This activity will perform two tests, both with a 5-element array (int runTimes[5]). See "How to Use zyBooks".Also note: If the submitted code tries to access an invalid array element, such as runTime[9] for a 5-element array, the test may generate strange results. Or the test may crash and report "Program end never reached", in which case the system doesn't print the test case that caused the reported message. #include <iostream>using namespace std; int main() {const int NUM_ELEMENTS = 5;int runTimes[NUM_ELEMENTS];int i; for (i = 0; i < NUM_ELEMENTS; ++i) {cin >> runTimes[i];} /* Your solution goes here */ return 0;} Please help me with this problem using c++.arrow_forward10arrow_forwardProgramming language: Java Write a program do the following: 1- ask student to enter name 2- ask student to enter the number of school subjects 3- Declare an array the same size as the number of school subjects. 4- ask the students to enter the marks in the array. 5- display the student name and the marks.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