Question

Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such as declaratic. Print the first array item, x[0]. Console X <terminated > Arrays [Java Application) C:\Program 1 d. Print the last array i1 2 3 4 5 6 7 After rotating by 3, the elements in the new array will appear in this sequence: 4 5 6 7123 Array x should be l3. We can use the Math.random method to generate random integers. For example, Math.random() generates a random integer greatThe main method imports java.util.ArrayList and creates an ArrayList that can hold strings. It also prints out the ArrayList5. Using your IDE, create a new project then add the existing file Medals.java to that project. The Medals.java file is postecall without stepping into the function code. Step out will take you out of a function that you are currently executing. k. S

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Since you have posted multiple problems I will solve only first problem and all of its sub-problems.

1.

Code

import java.util.*;
class Array{
  
public static void main(String[] args){
//a)
double[] x = new double[] {8,4,5,21,7,9,18,2,100};
//b)
System.out.println("Length of x : " + x.length);
//c)
System.out.println("x[0] : " + x[0]);
//d)
System.out.println("x[8] : " + x[8]);
//e)
System.out.println("x[x.length - 1] : " + x[x.length - 1]);
//f)
for(int i = 0; i < 9; i++)
System.out.println(x[i]);
//g)
for(int i = 0; i < 9; i++)
System.out.println("x["+i+"] : " + x[i]);
//h)
for(int i = 8; i >= 0; i--)
System.out.println("x["+i+"] : " + x[i]);
//i)   
for(double element : x)
System.out.println(element);
}
}

Output

Length of x: 9 x[0] : 8.0 x[8] : 100.0 x[x.length - 1) : 100.0 8.0 4.0 5.0 21.0 7.0 9.0 18.0 2.0 100.0 x[0] : 8.0 x[1] : 4.0

.x[0] : 8.0 x[1] : 4.0 x[2] : 5.0 x[3] : 21.0 x[4] : 7.0 x[5] : 9.0 x[6] : 18.0 x[7] : 2.0 X[8] : 100.0 X[8] : 100.0 x[7] : 2.

Add a comment
Know the answer?
Add Answer to:
Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such...
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
  • Array lists are objects that, like arrays, provide you the ability to store items sequentially and...

    Array lists are objects that, like arrays, provide you the ability to store items sequentially and recall items by index. Working with array lists involves invoking ArrayList methods, so we will need to develop some basic skills. Let's start with the code below: The main method imports java.utii.ArrayList and creates an ArrayList that can hold strings by using the new command along with the ArrayList default constructor. It also prints out the ArrayList and, when it does, we see that...

  • 1.The following statement gets an element from position 4 in an array named myArray: x =...

    1.The following statement gets an element from position 4 in an array named myArray: x = myArray[4]; What is the equivalent operation using an array list named list.? A x = list.get(); B x = list.get(4); C x = list.get[4]; D x = list[4]; 2.Consider the following code snippet: ArrayList<Integer> num1 = new ArrayList<Integer>(); int data; Scanner in = new Scanner(System.in); for (int i = 0; i < 5; i++) { data = in.nextInt(); num1.add(data); if (data == 0 &&...

  • Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring...

    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...

  • CT143 : Intro to C++ Lab 15: Array Practice Instructions Complete each of the C++ activities...

    CT143 : Intro to C++ Lab 15: Array Practice Instructions Complete each of the C++ activities described below in a single source file Label each activity with its own heading using comments. Activities: 1) Favorite numbers a. Declare and initialize an array of 10 integers as a single statement using a name of your choice. b. Output the result of adding the 1st and 5th members of the array. C. Subtract the 4h member from 3 times the 10th member...

  • 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...

  • C++ Lab 11 – Is This Box a Magic Box? Objectives: Define a two dimensional array Understand h...

    C++ Lab 11 – Is This Box a Magic Box? Objectives: Define a two dimensional array Understand how to traverse a two dimensional array Code and run a program that processes a two dimensional array Instructions: A magic square is a matrix (two dimensional arrays) in which the sum of each row, sum of each column, sum of the main diagonal, and sum of the reverse diagonal are all the same value. You are to code a program to determine...

  • I just need an algorithm for this please! I have C++ code for it but I dont know how to creat an ...

    I just need an algorithm for this please! I have C++ code for it but I dont know how to creat an algorithm .. CSE 1311-Project 4 Part I: Create and print out the two arrays: (Be sure to do this first) You are allowed to hard code these arrays into your program. You can also put the data into a file and read the information into the program. The data is as follows: 150 250 Anne Bob Ralph 305...

  • Lab Objectives Be able to write methods Be able to call methods Be able to declare...

    Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...

  • Write in Java! Do NOT write two different programs for Deck and Card, it should be...

    Write in Java! Do NOT write two different programs for Deck and Card, it should be only one program not 2 separate ones!!!!!! The Learning Goal for this exercise is to use and understand and know the difference between arrays and array lists. !!!!Use at least one array defined in your code and two array lists defined by the operation of your code!!!! The array should be 52 elements and contain a representation of a standard deck of cards, in...

  • I need help making my array into a function that can called by the main function...

    I need help making my array into a function that can called by the main function using my program. This is C programming int prime (int x) { int i; i = 2; while (i < x) { if (x % i == 0) return 0; i++; } return 1; } int main (void){ int n; scanf ("%d", &n); if (n < 1) { printf ("Error: at least one data value must be provided.\n"); return 1; } int a[n]; int...

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