Question

Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring a variable, you usually want to
Step 1: Getting started with the header At the beginning of each programming assignment you must have a comment block with th
Step 4. Request the user input and declare a double array Please use the Scanner object you defined to request an integer fro
Sample Output Below is an example of what your output should roughly look like when this lab is completed. Text in RED repres
image.png
// --> 1/ store this element at the ith position of the array // --> 11 ========== Display and sum the arrays elements =====
0 0
Add a comment Improve this question Transcribed image text
Answer #1
abc

CODE TEXT

package com.abc.example;

import java.util.Scanner;

public class Lab8 {

public static void main(String[] args) {

int arraySize;

double sumOfArray = 0.0;

Scanner scan = new Scanner(System.in);

//REQUESTING ARRAY SIZE FROM USER

System.out.println("How many elements in the array?");

arraySize = scan.nextInt();

//DECLARING ARRAY

double[] array = new double[arraySize];

//FILLING THE ARRAY

for (int i = 0; i < array.length; i++) {

System.out.println("Please enter next value: ");

array[i] = scan.nextDouble();

}

//DISPLAY THE ARRAY

for (int i = 0; i < array.length; i++) {

System.out.print(array[i] + " ");

}

//SUMMATION OF ARRAY ELEMENTS

for (int i = 0; i < array.length; i++) {

sumOfArray = sumOfArray + array[i];

}

System.out.println("\nThe sum of array elements is " + sumOfArray);

}

}

CODE SCREENSHOT

CODE OUTPUT:

Code has been provided, so that you may add any additional comment if you want.

Hope this helps. Please upvote. Thanks !!

Add a comment
Know the answer?
Add Answer to:
Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab #7 CSE110 - Arizona State University Topics • Basic arrays Coding Guidelines • Give identifiers...

    Lab #7 CSE110 - Arizona State University Topics • Basic arrays Coding Guidelines • Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). • Keep identifiers to a reasonably short length. • Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects). • Use tabs or spaces to indent code within blocks (code surrounded by braces)....

  • Following the instruction This is c++ programming Lab Tasks: 1. Define a dynamic array class in...

    Following the instruction This is c++ programming Lab Tasks: 1. Define a dynamic array class in DynamicArray .h and DynamicArray.cpp files, according to the following UML class diagram: DynamicArray - int arrySize; - int currentSize; int* arrayPtr; + DynamicArray(int size) // Explicit constructor, which you define- allocate space in dynamic memory for an integer array of the given size. + DynamicArray) // Explicit destructor, which you define-de allocate dynamic memory. + additem(int item): bool // Set the value of the...

  • Create three variables for an int array, the size of the array, and a Scanner object...

    Create three variables for an int array, the size of the array, and a Scanner object to read keyboard input. Ask the user to specify the size of the array and then construct an int array of that size. Next, use a for loop to continuously ask the user to specify values for each location in the array. Lastly, print contents of the array as a histogram using the asterisk character (*). This will require using nested for loops. The...

  • Write a C program convert.c that converts each number in an array by the sum of...

    Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...

  • Assume the following declarations have been made in main(): int howmany; Scanner kb = new Scanner(System.in);...

    Assume the following declarations have been made in main(): int howmany; Scanner kb = new Scanner(System.in); Random r = new Random(); Write code to do the following: Use a while loop to prompt the user for how many numbers are to be entered. If the user does not enter a positive number (a number greater than 0), display a message saying the number must be positive and to try again. Store this value in the howmany variable. Declare an integer...

  • You are to write three functions for this lab: mean, remove, display. Download the main.cpp file...

    You are to write three functions for this lab: mean, remove, display. Download the main.cpp file provided to get started. Read the comments in the main function to determine exactly what the main function should do. //include any standard libraries needed // - Passes in an array along with the size of the array. // - Returns the mean of all values stored in the array. double mean(const double array[], int arraySize); // - Passes in an array, the size...

  • (you can use any language) Write an algorithm that works with an array of size N...

    (you can use any language) Write an algorithm that works with an array of size N and shows the user the next menu: 1. Fill array. 2. Get sum of array elements 3. Get the maximum value of the array elements 4. Get the minimum value of the array elements. 5. Exit

  • Program Overview This brief exercise is designed for you to consider how reference variables behave when...

    Program Overview This brief exercise is designed for you to consider how reference variables behave when you are passing them as arguments by-value. Instructions Name your class References.java. 1. Implement the following methods. 1.1 Method name: readStudentNames Purpose: This method accepts an array of strings as a parameter. It loops through the array and asks the user to input names. It populates the array of strings with the names. Parameters: an array of Strings, stringArray Return type: void In the...

  • Introduction to Arrays. Please make sure program compiles :) int numlist[8]; // declare int array that...

    Introduction to Arrays. Please make sure program compiles :) int numlist[8]; // declare int array that can store 8 values If we wish to fill the array numlist with the integers typed from the keyboard, you can use a for loop. Here is a for loop that will allow you to enter 8 values from the keyboard and will store them in the array numlist. Notice that we have used the variable i as an index for array numlist for...

  • Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such...

    Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such as declaration, initialization, storing, retrieving, and processing elements. • Effectively manipulating and using ArrayList objects. • Becoming familiar with the use of arrays as method arguments and how array elements are passed to and returned from the called method. • Mastering the use of various debugging tools available on the Eclipse IDU. Important: EVERY one of the following Activities MUST be in a separate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT