1 Sample Code
2 Exercises
- Print out the elements of the following array: int [] numbers = {1,2,3,4,5};
- Declare and initialize a String array containing the days of the week. Print out a random day.
- Output the sum of the elements in this array: int [] values = {3,5,4,7,2,3};
- Output the average of the elements in this array: int [] values = {3,4,5,6};
- Declare an int array of length 5. Use a for loop to prompt for 5 numbers and enter them into the array. Print out the array.
- Declare an int array of length 4. Use a for loop to prompt for 4 numbers and enter them into the array. Print out the average of the four numbers
- The following code will convert a String s to an array of characters c. Print out the characters: String s = “This is a string”; char [] c = s.toCharArray();
- Use what you learned in the last question to count the number of times the letter e occurs in the String “I never saw a purple cow”
Like this:
Like Loading...
Related
Published by Tony Ballantyne
Writer and Tech blogger
View all posts by Tony Ballantyne