In this lab, you will get acquainted with the workings of arrays. Follow instruc
ID: 3925315 • Letter: I
Question
In this lab, you will get acquainted with the workings of arrays. Follow instructions below directly in the code. import java.util.scanner; public class Main {public static void main(String[] args) {Scanner input = new Scanner (System.in); System.out.println("How many items do you want to store in the array?"); int size =/" complete code here */; int[] A =/* complete statement here to define an array of integer of the size specified above */; for (/* complete description of for loop here */) {System.out.println("Enter item number" + (i+1) + ":");/* write statement here to fill information inside the array A */;} System.out.println("The address of your array is " +/* complete here */); System.out.println("The content of your array is {"); for (/* complete description of for loop here */) {/* complete with statements here to print out the content of the array separated with commas */} Sysem.out.print(")");Explanation / Answer
Main.java
import java.util.Scanner;
public class Main {
public static void main(String arg[]){
Scanner input = new Scanner(System.in);
System.out.println("how many items do you want to store in an array: ");
int size = input.nextInt();
int[] A = new int[size];
for(int i=0; i<size; i++){
System.out.println("Enter item number "+(i+1)+": ");
A[i] = input.nextInt();
}
System.out.println("The address of your array is "+A.length);
System.out.println("the content of your array is {");
for(int i=0; i<size; i++){
System.out.print(A[i]+", ");
}
System.out.println("}");
}
}
Output:
how many items do you want to store in an array:
5
Enter item number 1:
3
Enter item number 2:
4
Enter item number 3:
2
Enter item number 4:
1
Enter item number 5:
5
The address of your array is 5
the content of your array is {
3, 4, 2, 1, 5, }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.