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
A pump is used to deliver water from a lake to an elevated storage tank. The pipe network consists of 1,800 ft (equivalent lengt
Nataly_w [17]

Answer:

h_f = 15 ft, so option A is correct

Explanation:

The formula for head loss is given by;

h_f = [10.44•L•Q^(1.85)]/(C^(1.85))•D^(4.8655))

Where;

h_f is head loss due to friction in ft

L is length of pipe in ft

Q is flow rate of water in gpm

C is hazen Williams constant

D is diameter of pipe in inches

We are given;

L = 1,800 ft

Q = 600 gpm

C = 120

D = 8 inches

So, plugging in these values into the equation, we have;

h_f = [10.44*1800*600^(1.85)]/(120^(1.85))*8^(4.8655))

h_f = 14.896 ft.

So, h_f is approximately 15 ft

7 0
3 years ago
Answer back to question for la ,lot points
Lerok [7]

Answer:

yes

Explanation:

yes

5 0
3 years ago
‏What is the potential energy in joules of a 12 kg ( mass ) at 25 m above a datum plane ?
Virty [35]

Answer:

E = 2940 J

Explanation:

It is given that,

Mass, m = 12 kg

Position at which the object is placed, h = 25 m

We need to find the potential energy of the mass. It is given by the formula as follows :

E = mgh

g is acceleration due to gravity

E=12\times 9.8\times 25\\\\E=2940\ J

So, the potential energy of the mass is 2940 J.

3 0
3 years ago
Who is/are the founder/founders of transistor? ​
den301095 [7]

Answer:

William Shockley, Walter Houser Brattain and John Bardeen.

Explanation:

It was built in 1947 and they won the novel peace prize in 1956

7 0
3 years ago
Read 2 more answers
In some companies, workers who increase the quantity or quality of their work receive a. benefits. c. performance bonuses. b. pe
Greeley [361]

Answer:

performance bonuses

Explanation:

3 0
3 years ago
Other questions:
  • Suppose that the president of a small island nation has decided to increase government spending by constructing three beach reso
    11·1 answer
  • The enthalpy of the water entering an actual pump is 500 kJ/kg and the enthalpy of the water leaving it is 550 kJ/kg. The pump h
    10·1 answer
  • A model of a submarine, 1:15 scale, is to be tested at 180 ft/s in a wind tunnel with standard sea-level air, while theprototype
    8·1 answer
  • Calculate the diffusion current density for the following carrier distributions. For electrons, use Dn = 35 cm2/s and for holes,
    6·1 answer
  • Consider a potato being baked in an oven that is maintained at a constant temperature. the temperature of the potato is observed
    14·1 answer
  • How can goal setting help with academic performance?
    13·1 answer
  • Which scientist was famous for his laws on gravity?
    10·2 answers
  • Calculate the radius of a circular orbit for which the period is 1 day​
    13·1 answer
  • The image shows the relative positions of Earth and the Sun for each of the four seasons. Earth travels in an elliptical orbit a
    11·2 answers
  • The team needs to choose a primary view for the part drawing. Three team members make suggestions:
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!