exercisesMarch508

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

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

View Full Document Right Arrow Icon
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.
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
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

This note was uploaded on 04/14/2008 for the course COMP 202 taught by Professor Verbrugge during the Winter '07 term at McGill.

Page1 / 5

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

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online