Menu

[Solved]Java Code Please Read Comments Add Code Required Linesline 1 Line 5 Program Summary Progra Q37196777

Java Code please read comments and add the code to requiredlines….LINE 1 to LINE 5

**********************************************************************
* Program Summary: This program demonstrates these basic Javaconcepts:
* – Creating an array based on user input
* – Accessing and displaying elements of the array
*
* The program should declare an array to hold 10 integers.
* The program should then ask the user for an integer.
* The program should populate the array by assigning the user-inputinteger
* to the first element of the array, the value of the first element+ 100 to
* the second element of the array, the value of the second element+ 100 to
* the third element of the array, the value of third element + 100to
* the fourth element of the array, and so on until all 10 elementsof the
* array are populated.
*
* Then the program should display the values of each of thearray
* elements onscreen. For example, if the user inputs 4, theoutput
* should look like this:
*
* Enter an integer and hit Return: 4
* Element at index 0: 4
* Element at index 1: 104
* Element at index 2: 204
* Element at index 3: 304
* Element at index 4: 404
* Element at index 5: 504
* Element at index 6: 604
* Element at index 7: 704
* Element at index 8: 804
* Element at index 9: 904
***********************************************************************/
package prg420week4_codingassignment;

// We need to import the following library if we want to usethe
// Scanner class to get user input.
import java.util.Scanner;

public class PRG420Week4_CodingAssignment {

public static void main(String[] args) {
  
// LINE 1. DECLARE AN ARRAY OF INTEGERS
  

// LINE 2. ALLOCATE MEMORY FOR 10 INTEGERS WITHIN THEARRAY.
  
  
// Create a usable instance of an input device
Scanner myInputScannerInstance = new Scanner(System.in);
  
// We will ask a user to type in an integer. Note that in thispractice
// code WE ARE NOT VERIFYING WHETHER THE USER ACTUALLY
// TYPES AN INTEGER OR NOT. In a production program, we would
// need to verify this; for example, by including
// exception handling code. (As-is, a user can type in XYZ
// and that will cause an exception.)
System.out.print(“Enter an integer and hit Return: “);
  
// Convert the user input (which comes in as a string even
// though we ask the user for an integer) to an integer
int myFirstArrayElement =Integer.parseInt(myInputScannerInstance.next());
  
// LINE 3. INITIALIZE THE FIRST ARRAY ELEMENT WITH THE CONVERTEDINTEGER myFirstArrayElement

  
// LINE 4. INITIALIZE THE SECOND THROUGH THE TENTH ELEMENTS BYADDING 100 TO THE EACH PRECEDING VALUE.
// EXAMPLE: THE VALUE OF THE SECOND ELEMENT IS THE VALUE OF THEFIRST PLUS 100;
// THE VALUE OF THE THIRD ELEMENT IS THE VALUE OF THE SECOND PLUS100; AND SO ON.

  
// LINE 5. DISPLAY THE VALUES OF EACH ELEMENT OF THE ARRAY INASCENDING ORDER BASED ON THE MODEL IN THE TOP-OF-CODE COMMENTS.

}
}

Expert Answer


Answer to Java Code please read comments and add the code to required lines….LINE 1 to LINE 5 **********************************… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *