1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mamont248 [21]
3 years ago
10

Write a program that adds the numbers 1 through 5 into the numbers ArrayList and then prints out the first element in the list.

Engineering
1 answer:
nekit [7.7K]3 years ago
6 0

Answer:

Answer code is given below along with comments to explain each step

Explanation:

Method 1:

// size of the array numbers to store 1 to 5 integers

int Size = 5;  

// here we have initialized our array numbers, the type of array is integers and size is 5, right now it is empty.

ArrayList<Integer> numbers = new ArrayList<Integer>(Size);

// lets store values into the array numbers one by one

numbers.add(1)

numbers.add(2)

numbers.add(3)

numbers.add(4)

numbers.add(5)

// here we are finding the first element in the array numbers by get() function, the first element is at the 0th position

int firstElement = numbers.get(0);

// to print the first element in the array numbers

System.out.println(firstElement);  

Method 2:

int Size = 5;  

ArrayList<Integer> numbers = new ArrayList<Integer>(Size);

// here we are using a for loop instead of adding manually one by one to store the values from 1 to 5

for (int i = 0; i < Size; i++)  

{

// adding the values 1 to 5 into array numbers

  numbers.add(i);  

}

//here we are finding the first element in the array numbers

int firstElement = numbers.get(0);  

// to print the first element in the array

System.out.println(firstElement);  

You might be interested in
You are designing the access control policies for a Web-based retail store. Customers access the store via the Web, browse produ
PolarNik [594]

Answer:

Object-Oriented Software Engineering Using UML, Patterns, and Java, 3e, shows readers how to use both the principles of software engineering and the practices of various object-oriented tools, processes, and products.

3 0
2 years ago
What is the differences between stack and queue?
Montano1993 [528]

Answer:

A stack is an ordered list of elements where all insertions and deletions are made at the same end, whereas a queue is exactly the opposite of a stack.

Explanation:

7 0
3 years ago
The fracture strength of glass may be increased by etching away a thin surface layer. It is believed that the etching may alter
UkoKoshka [18]
Maybe it willl be I don’t know
7 0
2 years ago
the increase of current when 15 V is applied to 10000ohm rheostat which is adjusted to 1000ohm value​
Anastasy [175]
Given data:
•) applied voltage = 15 V
•). Resistance = 1000 ohm

Required:
•). The magnitude of current= ?

•••••••••••••SOLUTION•••••••••••••

We can find the relation ship between current, voltage and resistance with the help of Ohms law.

According to ohms law;

V= IR.

Rearranging the above equation;

I= V/ R

Putt the values in the above equation; we get

I= 15V/ 1000ohm

I = 0.015 A( ampere)

••••••••••••••• CONCLUSION•••••••

The value of the current would be 0.15 ampere when Resistance is equal to 1000 and that of Voltage is equal to 15 V.
4 0
3 years ago
What does it take to launch a rocket in space?
Dafna11 [192]
To get rockets into orbit, they need much more thrust than the amount that will get them up to the required altitude. They also need sufficient thrust to allow them to travel with very high orbital speed. ... If speed is less than this, an object will fall back to the Earth
3 0
3 years ago
Read 2 more answers
Other questions:
  • What are the disadvantages of using 3D ink jet printing ??
    8·1 answer
  • Identify each statement as referring to a series or parallel circuit.
    15·1 answer
  • The denominator of a fraction is 4 more than the numenator. If 4 is added to the numenator and 7 is added to the denominator, th
    15·1 answer
  • A column has a 4.8 cm by 8.7 cm rectangular cross section and a height 4 mm . The column is fixed at both ends and has a lateral
    6·1 answer
  • Air expands through an ideal turbine from 1 MPa, 900 K to 0.1 MPa, 500K. The inlet velocity is small compared to the exit veloci
    10·1 answer
  • Suppose that we have a 1000 pF parallel-plate capacitor with air dielectric charged to 1000 V. The capacitors terminals are open
    13·1 answer
  • A lightbulb has a fixed negative and positive connector. You cannot swap positive and negative sides of a lightbulb in a circuit
    9·2 answers
  • A reservoir rock system located between a depth of 2153m and a depth of
    10·1 answer
  • What are the BENEFITS and RISKS of using automobiles?
    10·1 answer
  • Workers who work with what kind of chemicals chemicals may require regular medical checkups on a more frequent basis as a result
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!