Week 9

Post date: Oct 30, 2019 10:37:38 AM

Arrays

6.1 Introduction to arrays

Recommended Self-Test Exercises:

    • p 385-386: Ex. 1, 2, 4-6.

    • p 403-404: Ex. 13.

Lab Exercises:

  1. Write an application that reads 10 grades, then displays the total, the average, the maximum and the minimum of those numbers.

  2. Write an application that inputs 10 numbers, each between 0 and 100, then display the list of numbers without repetitions (duplicate values are not printed more than once).

  3. For example: if the user enters 5 2 1 6 2 5 1 4 2 1,

  4. The program should display: 5 2 1 6 4

  5. Given an array of integers, write a java code that allows to check if the array is “palindromic”. A palindromic array is a symmetric one:

    1. For example the arrays {1, 6, 4, 6, 1} and {2, 5, 8, 8, 5, 2} are both palindromic, but the array {3, 7, 5, 3} is not.

  6. Write a program that reads a sequence of 10 integers into an array and then computes the alternating sum of all elements in the array:

    1. For example if the array is : {1, 4, 9, 16, 9, 7, 4, 9, 11} then it computes : 1 - 4 + 9 - 16 + 9 - 7 + 4 - 9 + 11 = -2

  1. Write a Java program to find the duplicate values of an array of integers

  2. Write a Java program to find the common elements between two arrays (string values)

  3. Write a Java program to find the second largest element in an array.

  4. Write a Java program to add two integer arrays of the same size