Concept explainers
Explanation of Solution
a. Declaring string array:
The statement which is used to declare “String” array with the values “Mercury”, “Venus&...
Explanation of Solution
b. Loop to display each element in the array:
//Class definition
public class Sample {
// define main function
public static void main(String[] args) {
// Declaration of string array
String[] scientists = {"Einstein", "Newton", "Copernicus", "Kepler"};
// Loop to read each element in scientists array
for(int i = 0; i<scientists.length; i++)
// Display contents of the scientists array
System...
Explanation of Solution
c. Loop to display total length of the all strings present in the array:
//Class definition
public class Sample {
// define main function
public static void main(String[] args) {
// Declaration of string array
String[] scientists = {"Einstein", "Newton", "Copernicus", "Kepler"};
// Declare and initialize the variable
int total = 0;
// Loop to read each element in scientists array
for(int i = 0; i<scientists.length; i++)
/* Using the length() method read the length of strings present in the array */
total += scientists[i]...
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
- do the following: - Create an array of the following temperature readings: 36, 5, 10, 24, 40, 31 - use a loop to find the sum of the elements in the array. -find the average of the numbers. if the average is more than 30 display the message "TOO HOT" on screen otherwise check if the average is between 15 and 30 display the message "MODERATE" otherwise display the message "TOO COLD".arrow_forwardProgramming language is C#arrow_forward2. Creates an array of Triangle type of size 10. Prompts the user to enter the index of the array, then displays the area of corresponding element value. If the specified index is out of bounds, display the message Out of Bounds.arrow_forward
- 5. Create an array that contents 10 integer elements, and let user randomly input 10 values and put into the array, Sorts array elements in ascending order, and then print out the array element.arrow_forwardA single statement that declares a variable and specifies array values as its content is called an array Select one: a.literal b.constructor C.element d.indexarrow_forwardIn order to access each element in an array, the Do...Loop statement needs to know the highest subscript in the array. True or False?arrow_forward
- JAVA:arrow_forwardDeclare a variable named num with an initial value of 0. Create a while loop that will print "Keep going" as long as the value of num is less than 5. Use window.alert() for displaying the output. Create a function named showProd that returns the product of n1 and n2. Using the new keyword, create an array named info with three (3) values: your first name, your nickname, and your last name.arrow_forwardHomework - identical arrays for one-dimensional: Write a test program which prompts a user to enter the size of two arrays as well as to fill their elements. After that, the program checks the same contents of the elements of the two arrays. If these arrays are equal, the program displays message which is "The two arrays are identical". If not equal, displaying "The two arrays are not identical". Write an equals method that reads two arrays and displays these messages above.arrow_forward
- Alert - don't use any AI platform to generate my answer and don't try to copy anything from other websites otherwise I'll reduce rating for sure and reportarrow_forwardCreate a flowchart that determines the perfect squares in an array.arrow_forward3- Write code that will prompt the user for 5 numbers and store them in a vector. Use a for loop. Make sure that you preallocate the vector!arrow_forward
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT