exercisesMarch508

# exercisesMarch508 - /Initialize the Array to the string...

This preview shows pages 1–5. Sign up to view the full content.

COMP202 Instructor: Ladan Mahabadi March 5, 2008 Write a program where the user enters a collection of positive numbers representing ages of a group people who have participated in a study. Store the ages in an array called age and write a method called average and given an input array of integers computes their average. Using this method, compute the average of the user’s ages array.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Joggling Strings: Fill out the missing lines of code the following implementation: /** * The following class creates an array of strings and then joggles the input counter-clock * wise **/ import java.util.Scanner; public class juggle { // This class has no private variables and contains only the main method public static void main(String[] args) { int num, juggleCount; String input, last; //Ask the user for the number of items to juggle and set that value to be num //Enter your code here: //Declare an array of strings of length num //Enter your code here: //Prompt the user to input the contents of the array

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //Initialize the Array to the string input by the user for (int i = 0; i < num; i++) { System.out.println("Please enter your string to be stored at index " + i); //Enter your code here: } //Display the full content of the array to the user for (int i = 0; i < num; i++) { System.out.println(" Content of cell " + i + " is: " + jArray[i]); System.out.println(); } //Juggle: //Ask the user how many times to joggle the array: System.out.println("How many times would you like the array to be juggled?"); juggleCount = scan.nextInt(); //Juggle the three strings below three times: // e.g. Apple, Orange, Kiwi ---> Kiwi, Apple, Orange ---> Orange, Apple, Kiwi while(juggleCount != 0) { //Enter your code here: } } Joggling Reversed: Rewrite the above code so that entries are juggled in the reverse order: // e.g. Apple, Orange, Kiwi ---> Orange, Kiwi, Apple ---> Kiwi, Apple, Orange...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern