Question: 1. What java statement would store the number of elements of an array? Give an example. 2. Define a constant to store a string with
1. What java statement would store the number of elements of an array? Give an example. 2. Define a constant to store a string with the value of Hello. When should you use constants? 3. Be able to write the Java code to declare an array list. Be able to write an enhanced for loop to output the values of the array list you created. Example Write the code to initialize an array list of prices for your favorite 5 food items. Call the arraylist foodItems. Create an enhanced for loop to output the values. 4. Write a method that is passed an array and then will return a value. Example Write a method that is passed an array and counts the values that are positive and returns this count. 5. Write a method that will manipulate a value and then print the results when passed a value. This array will not return any value. Example - Write a method that prints the letter grade when passed a number grade. 6. Understand how arrays are passed to methods and what that means for the array. What is the output of the following code and specify a stack diagram to show the state of the memory at the end of the method. import java.util.*; public class Rocket { public static void main(String[] args) { String[] twos = {AB, BC, CD}; performAction(twos); System.out.println(Arrays.toString(twos)); } public static void performAction(int [] data) { for (int i =0; i < data.length; i++) { data[i] = data[i] + Z; } } } 7. Be able to walk through a 2-dimensional array and state the output from the array. int [][] add = new int [10][10] for (int i = 0; i < 10; i++) { for(int j = 0; j < 10; j++) { add[i][j] = (i + j); System.out.print(add[i][j] + ); } System.out.println(); } What is outputted from this code? 8. Write a method to return a calculation from an array. Write a method that will return the largest number from the array passed to the method. 9. Be able to walk through a program that reads data from a file and outputs data to a file, stating what is in the file once the file is written. File inputFile = new File(inputFileName); Scanner in = new Scanner(inputFile); PrintWriter out = new PrintWriter(outputFileName); double highest = 0; while (in.hasNext()){ int grade = in.nextInt(); if (grade > highest) highest = grade; } out.printf("The highest grade is: %10.d%n", highest); What would be outputted if the input file consisted of the following ints 56 76 45 90 34 88? Write pseudocode to read data from a file and manipulate that data as we have done in class activities.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
