Programming Homework Help

Programming Homework Help. Java Language Project

 

1.  Declare an array to hold eight integers. Use a for loop to add eight random integers, all in the range from 50 to 100, inclusive, to this array. Duplicates are okay. Next, pass the array to a method that sorts the array and returns another array containing only the largest and smallest elements in the original array. Print these two values in main. Then use a foreach loop to display all elements of the sorted array on one line separated by a single space. This latter loop should also count the odd and even numbers in the array and determine the sum of all elements in the array.

SAMPLE OUTPUT

The lowest element is 59

The highest element is 96

Here is the array

59 64 76 77 80 88 91 96 

Evens: 5, odds: 3

Total: 631

2. Write a method named sumInts that can take a variable number of int arguments (see page 264-265) and return the sum of these arguments. The ints to be summed up must be entered as command line arguments. Command line arguments can be simulated in Eclipse. Watch the video. In the main method, display the ints that were entered on the command line. Then execute sumInts and display the sum it returns.
TWO SAMPLE OUTPUTS

Passing [1, 2, 3, 4, 5]
Sum is 15

Passing [10, 20, 30]
Sum is 60

3. Create an ArrayList of strings to store the names of celebrities or athletes. Add five names to the list. Process the list with a for loop and the get() method to display the names, one name per line. Pass the list to a void method. Inside the method, Insert another name at index 2 and remove the name at index 4. Use a foreach loop to display the arraylist again, all names on one line separated by asterisks. After the method call in main, create an iterator for the arraylist and use it to display the list one more time. See Sample Output.

SAMPLE OUTPUT

Here is the list

Lionel Messi

Drake

Adele

Dwayne Johnson

Beyonce

Here is the new list

* Lionel Messi * Drake * Taylor Swift * Adele * Beyonce

Using an iterator, here is the list

Lionel Messi

Drake

Taylor Swift

Adele

Beyonce

Programming Homework Help