Question

In: Computer Science

Exercise 18: Running Ex. 16 You will write exercise 16 into a program and make it...

Exercise 18: Running Ex. 16 You will write exercise 16 into a program and make it run. Note that there are two parts, 16A and 16B. Type 16A into a program called Exercise16A and type 16B into a program called Exercise16B. Be sure label each section using comments. You may notice that additional code needs to be written for the program to run. For example, Section I assumed that an array was already declared and initialized. Here, you will have to declare and initialize an array with random values to test it.

Section A. Declare and initialize an array firstNames containing the following names: Jane, Jim, Beth, Mary, Sara, and Bob. Remember to choose the correct data type for the array elements.

Section B. Using a FOR loop, output the elements of the array firstNames so that they are displayed on the same line and separated by a space. Use .length to get the length of the array.


this is for java language

Solutions

Expert Solution

public class Exercise16A {
    public static void main(String[] args)
    {
        /**
         * Declare and initialize an array firstNames containing the 
         * following names: Jane, Jim, Beth, Mary, Sara, and Bob.
         */
        String[] firstNames ={"Jane","Jim","Beth","Mary","Sara","Bob"};
    }
}

//================================================

public class Exercise16B {
    public static void main(String[] args)
    {
        /**
         * Declare and initialize an array firstNames containing the
         * following names: Jane, Jim, Beth, Mary, Sara, and Bob.
         */
        String[] firstNames ={"Jane","Jim","Beth","Mary","Sara","Bob"};
        /**
         * Using a FOR loop, output the elements of the array firstNames
         * so that they are displayed on the same line
         * and separated by a space. Use .length to get the length of the array.
         */
        //Since array index starts with 0 so firstNames[0] will contain "Jane" and
        // so on.
        for (int i = 0; i <firstNames.length ; i++) {
            //
            System.out.print(firstNames[i]+" ");
        }
        
    }
}

//Output

//If you need any help regarding this solution ........ please leave a comment ...... thanks


Related Solutions

Test #3 - Chapters 15-17 EX.16-163 MC.16-125 MC.16-050 MC.17-069 MC.15-150 MC.15-071 MC.16-083.ALGO EX.17-174 MC.17-074 EX.16-162 EX.16-170...
Test #3 - Chapters 15-17 EX.16-163 MC.16-125 MC.16-050 MC.17-069 MC.15-150 MC.15-071 MC.16-083.ALGO EX.17-174 MC.17-074 EX.16-162 EX.16-170 MC.16-060 MC.16-071 EX.16-172 EX.15-169 MC.16-124 MC.16-108 MC.15-068 EX.17-163 Hide or show questions Progress:8/19 items Calculator Zang Co. manufacturers its products in a continuous process involving two departments, Machining and Assembly. Prepare journal entries to record the following transactions related to production during June: If an amount box does not require an entry, leave it blank. a. Materials purchased on account, $180,000. b. Materials requisitioned...
Chapter 5 Homework Assignment (part 2) PE.05-03.ALGO PE.05-04.ALGO EX.05-04 EX.05-11 EX.05-12 EX.05-14.ALGO EX.05-15.ALGO EX.05-16.ALGO EX.05-17.ALGO EX.05-18.ALGO...
Chapter 5 Homework Assignment (part 2) PE.05-03.ALGO PE.05-04.ALGO EX.05-04 EX.05-11 EX.05-12 EX.05-14.ALGO EX.05-15.ALGO EX.05-16.ALGO EX.05-17.ALGO EX.05-18.ALGO Hide or show questions Progress:7/10 items eBook Show Me How Calculator Print Item Posting a Purchases Journal The purchases journal for Newmark Exterior Cleaners Inc. follows. The accounts payable account has a March 1, 20Y2, balance of $605 for an amount owed to Nicely Co. No payments were made on creditor invoices during March. PURCHASES JOURNAL Page 16 Date Account Credited Post. Ref. Accts.  ...
Question 1 In this exercise, you are required to do a program analysis and write a...
Question 1 In this exercise, you are required to do a program analysis and write a program for a system that computes a speeding ticket cost. The charge is calculated as follows: P20 for every kilometre above the speed limit, plus P100 standard charge. E.g. If the speed limit is 60 km/hour and you are driving at 75 km/hour. The charge will be P400. If the speed is equal to or under the speed limit, then there is no charge....
JAVA PROGRAM (Make sure that programs are running. Please discuss, if there is any compilation or...
JAVA PROGRAM (Make sure that programs are running. Please discuss, if there is any compilation or run error.) Q. 1 Calculate the expression a)         x= 7.0 + (12 %3)*5 – 3;                    b)         x= 7 + (11 / 2)*5 + 3;            Q 2: Write a program that prompts the user to enter five test scores and then prints the average test score. (Assume that the test scores are decimal numbers.) Q 3. Write a program that prompts the capacity, in gallons,...
C++ for Mac (Xcode) For this exercise, you will write a program that includes four function...
C++ for Mac (Xcode) For this exercise, you will write a program that includes four function definitions. You will also write a main() function that calls these four functions to demonstrate that they work as expected. The four functions are: 1. printExitMessage() : This function prints a message to the screen saying something like "Thanks for using this software. Goodbye." 2. getMin(): This function takes two float inputs and returns the lesser of the two float values. For example, if...
Instructions Write a program to implement the algorithm that you designed in Exercise 19 of Chapter...
Instructions Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1. Your program should allow the user to buy as many items as the user desires. Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience. TEXT ONLY PLEASE (PLEASE NO PDF OR WRITING) C++ CODE Exercise 19 Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200...
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise...
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1. Your program should allow the user to buy as many items as the user desires. Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience. Exercise 19 Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200 or more, then the shipping and handling...
11.2 Exercise 2: You are required to write a program that creates a float array of...
11.2 Exercise 2: You are required to write a program that creates a float array of size 90. Using a for loop, populate the array element whose index is the value of the loop variable with the value of the loop variable (e.g. array[0] = 0, array[1] = 1 etc.) Using a second loop display the loop index and the value in the array - each pair of numbers is to be displayed on a new line. Hi, could you...
We have a list of runner and their running time, write a program in Java to...
We have a list of runner and their running time, write a program in Java to show the fastest runner and their time.
For JavaSript the hexadecimal (base 16) number 9a. In a JavaScript program you would write it...
For JavaSript the hexadecimal (base 16) number 9a. In a JavaScript program you would write it as: 0x9a. How would you write it in the more familiar base 10? Here is how to solve this. a.       Recall that a "normal" base 10 number has a ones place, a tens place, a hundreds place, a thousands place, etc. Another way to put it is, it has a 100's place (100=1), a 101's (101=10), a 102's place (102=100), a 103's place (103=1,000), etc....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT