Java Code please read comments and add the code to required lines....LINE 1 to LINE 5
**********************************************************************
* Program Summary: This program demonstrates these basic Java
concepts:
* - 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-input
integer
* 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 + 100
to
* the fourth element of the array, and so on until all 10 elements
of the
* array are populated.
*
* Then the program should display the values of each of the
array
* elements onscreen. For example, if the user inputs 4, the
output
* 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 use
the
// 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 THE
ARRAY.
// 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 this
practice
// 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 CONVERTED
INTEGER myFirstArrayElement
// LINE 4. INITIALIZE THE SECOND THROUGH THE TENTH ELEMENTS BY
ADDING 100 TO THE EACH PRECEDING VALUE.
// EXAMPLE: THE VALUE OF THE SECOND ELEMENT IS THE VALUE OF THE
FIRST PLUS 100;
// THE VALUE OF THE THIRD ELEMENT IS THE VALUE OF THE SECOND PLUS
100; AND SO ON.
// LINE 5. DISPLAY THE VALUES OF EACH ELEMENT OF THE ARRAY IN
ASCENDING ORDER BASED ON THE MODEL IN THE TOP-OF-CODE COMMENTS.
}
}
import java.util.Scanner;
public class PRG420Week4_CodingAssignment {
public static void main(String[] args) {
// LINE 1. DECLARE AN ARRAY OF
INTEGERS
int arr[];
// LINE 2. ALLOCATE MEMORY FOR
10 INTEGERS WITHIN THE ARRAY.
arr = new int[10];
// 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 this practice
// 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 CONVERTED INTEGER
// myFirstArrayElement
arr[0] = myFirstArrayElement;
// LINE 4. INITIALIZE THE SECOND
THROUGH THE TENTH ELEMENTS BY ADDING
// 100 TO THE EACH PRECEDING
VALUE.
// EXAMPLE: THE VALUE OF THE SECOND
ELEMENT IS THE VALUE OF THE FIRST
// PLUS 100;
// THE VALUE OF THE THIRD ELEMENT
IS THE VALUE OF THE SECOND PLUS 100;
// AND SO ON.
for (int i = 1; i < 10;
i++)
arr[i] = arr[i -
1] + 100;
// LINE 5. DISPLAY THE VALUES OF
EACH ELEMENT OF THE ARRAY IN ASCENDING
// ORDER BASED ON THE MODEL IN THE
TOP-OF-CODE COMMENTS.
for (int i = 0; i < 10;
i++)
System.out.print(arr[i] + " ");
}
}
Java Code please read comments and add the code to required lines....LINE 1 to LINE 5...
Suppose v is an array with 100 int elements. If 100 is assigned to v[100], what happens? Show the code. An array of 1000 integers is declared. What is the largest integer that can be used as an index to the array? Shows the code. Consider the declaration: int v[1]; What is the index of the last element of this array? Declare an array named a of 10 int elements and initialize the elements (starting with the first) to the...
read the code and comments, and fix the program by INSERTING the missing code in Java THank you please import java.util.Scanner; public class ExtractNames { // Extract (and print to standard output) the first and last names in "Last, First" (read from standard input). public static void main(String[] args) { // Set up a Scanner object for reading input from the user (keyboard). Scanner scan = new Scanner (System.in); // Read a full name from the user as "Last, First"....
Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring a variable, you usually want to initialize it. Remember you cannot initialize a number with a string. Remember variable names are case sensitive. Use tabs or spaces to indent code within blocks (code surrounded by braces). Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Problem...
Matlab. Please add comments. Thank you in advance. 15. Write a code that can read in a string and replaces all vowels with x's 16. Write a function that reads in a D array of any length, u, and swaps elements of the array in the following way. The first and last element are swapped. The second and second to last element are swapped. The third and third to last element are swapped, and so on until all the elements...
Design Java (source code) a program (name it IndexOfLargest) to find the index of the first largest value in the array. Note that the largest value may appear more than once in the array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method findIndex() that takes a single-dimensional array of integer values and return the index of the first...
*C CODE* 1. Declare an array of doubles of size 75 called scoreBonus and initialize all the elements in the array to 10.5 2. Declare an array of integers called studentNumbers The array can hold 112 integers Prompt and get a number from the user for the third element in the array Prompt and get a number from the user for the last element in the array
daily21. Computing 1. C programming Please provide comments and write pre-condition and post-condition for the function. Description Create a project called Daily21. Add a source file called daily21.c into the project. In this exercise, you will practice working with an array of integers. In the main function, you first need to create an integer array with 10 elements in t. Use a loop to read 10 integers from the user and store the values to the array (in the order...
C# ONLY INCLUDE BOTH PSUDEO CODE AND SOURCE CODE!!!! Design (pseudocode) and implement (source code) a program (name it IndexOfLargest) to find the index of the first largest value in the array. Note that the largest value may appear more than once in the array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method findIndex() that takes a single-dimensional...
Must be done in Java. Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. CODE PROVIDED: import java.util.ArrayList; import java.util.Scanner; public class Problem3 { public static void main( String [] args ) { Scanner in = new Scanner( System.in ); //PLEASE START YOUR WORK HERE //********************************************************** //********************************************************** // PLEASE END YOUR WORK HERE System.out.print("END OF OUTPUT"); } } 20 points! PROBLEM 3: EXTENDED FAMILY Complete this...
please answer correctly and follow the code structure given [JavaFX/ Exception handing and text I/O] 1. Write a program for the following. NOTE that some of these steps are not dependent on each other. Using methods is mandatory. Make sure to use methods where it makes sense. a. Ask the user for a series of integers entered from the keyboard. Use a sentinel value such as 999 to end the input process. If the entered values are not integers, throw...