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 (4th Edition) (What's New in Computer Science)
- Arrays where the index is a string value. O a. Associative O b. Positive O c. Numeric O d. Nonearrow_forwarda. Create a 1D array of integers to store 50 integers. b. Store values from 0 to 49 into the array you just created. c. Create a new String Object using no-arg constructor. d. Using for loop append the array elements one by one to the String (one per loop iteration) e. Record and display a run-time it took to append all integers to the String (record run-time of 1.d.)). E.g. "It took nanoseconds to append 50 integers to the Stringarrow_forwardManhattan skyline def manhattan_skyline(towers):This classic problem in computational geometry (essentially, geometry that can be done using only integer arithmetic; yes, that is an actual thing) is best illustrated by pictures and animations such as those on the page "The Skyline problem", so you can first check that it out to get an idea of what is going on. Given a list of rectangular towers as tuples (s, e, h) where s and e are the start and end x-coordinates (satisfying e>s) and h is the height of that tower, compute and return the total visible area of the towers, being careful not to double count two or more towers that are partially overlapping. All towers share the same flat ground baseline at the height. The classic solution illustrates the important sweep line technique that starts by creating a list of precisely those x-coordinate values where something relevant to the problem takes place. In this problem, the relevant x-coordinates are those where some tower either…arrow_forward
- Palindrome Checkercreate a JavaScript program that checks if phrasesentered by the user are palindromes. A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as “SIR”,“raceBIKE”, “Never odd or even”, “20/1/20”. The program should prompt the user to typein a phrase that is at least three characters long, and then tell the user whether the phrasewas a palindrome. Note, the decision should be based solely on letters and numericaldigits, and so it should not consider other characters, such as spaces or exclamationmarks, even though these might be entered by the user. when checking palindromes.A. Select your test data with care. Both palindromes and non-palindromes would be included in this. Provide examples that are text, numeric, and mixed; ignore any additional characters and spaces; andB. Ask the user for the word and then read their input. To verify that their input string has been read correctly, test this by displaying…arrow_forwardUsing c++ write a program Program : Date Printer Write a program that reads a char array from the user containing a date in the form mm/dd/yyyy. It should print the date in the form March 12, 2014. For example Enter Date 5/14/2019 May 14, 2019 Validation Required: Month should be less than 13, day should be less than 31.arrow_forwardName format: You must use String object and not StringBuffer or StringBuilder. Many documents use a specific format for a person's name. Write a program that take one Line as an input. Example: Scanner input = new Scanner(System.in); System.out.println(“Enter firstName middleName lastName separated by at least one blank, It may have more than one blank separating firstName middleName lastName."); Input sample : Pat Silly Doe || Note these are separated by at least one blank. String line = input.nextLine() Ex: If the input is: Pat Silly Doe the output is: Doe, P.S. If the input has the form: firstName lastName the output is: lastName, firstInitial. Ex: If the input is: Julia Clark the output is: Clark, J. Please submit the .java source file and the sample run in a text file. Thanksarrow_forward
- Word Sleuth Puzzle Programarrow_forwardPython Language: Word Sleuth Programarrow_forwardUsing C++ Language Modify the provided code as follows. • Declare another array of the same size and type and call it above_average. • Calculate the average height of the 12 students. • In a loop of your choice, check if the height of an individual student is larger than the average. If it is larger than the average, copy this element to the above _average array. Note that the above_average array will most likely have a smaller number of elements than the original height array. This also means that the locations of a specific student’s height in the two arrays may not be the same after copying. So, you will need a separate counter to keep track of elements in the new array. • Display the content of the new array as well as the average with suitable prompt. code so far: #include <iostream>using namespace std; int main(){ const int SIZE=12; int sumHeight=0; int height[SIZE]; int above_average[SIZE]; double average; for(int i=0;i<SIZE;++i) {…arrow_forward
- 99.arrow_forwardRest of code in image / This is a bad programming style since it is using goto. // This is an spagetti code and not working.// Use function to display menu, and display game rules,// Use different color for text display.// fix it so it works any way you like./*HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE); // Write 16 lines in 16 different colors. for (int color = 0; color < 16; color++) { SetConsoleTextAttribute (screen, color); cout << " Hello World!" << endl; Sleep(400); // Pause between lines to watch them appear } // Restore the normal text color) SetConsoleTextAttribute(screen, 7);*/#include <iostream>#include <windows.h>using namespace std;int main(){ //textbackground(WHITE); //textcolor(RED); system("cls"); char ch, a[20], ch2; int num = 100, rnum, guess, count, ch1, c = 0; cout << "**********************************************************"<<endl; cout << "*…arrow_forwardWrite a C++ (visual studio) program that examines a list of numbers to find the smallest value. The list should include 10,000 random whole numbers that range from -1,000,000 to 1,000,000. The program should display the lowest value in the list and the number of the element that contains that value.And create a pseudocode explaining the steps. (if you would give to someone to create the program) The program must have:Declare an array in the main() function that will hold 10,000 integers. Pass the array to the other functions as necessary. Use a reliable algorithm to produce random integers within a given range. Note: stran()/rand() is NOT a reliable random number algorithm. The function should accept the minimum and maximum values that will be generated and return an integer.Examine the array to find the smallest value. Return the smallest value and the number of the element that contains the smallest value.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage