Write a program that creates an integer array with 40 elements in it. Use a for loop to assign values to each element of the array so that each element has a value that is triple its index. For example, the element with index 0 should have a value of 0, the element with index 1 should have a value of 3, the element with index 2 should have a value of 6, and so on.

Answers

Answer 1

Answer:

public class Main

{

public static void main(String[] args) {

 int[] numbers = new int[40];

 for (int i=0; i<40; i++){

     numbers[i] = i * 3;

 }

 for (int i=0; i<40; i++){

     System.out.println(numbers[i]);

 }

}

}

Explanation:

*The code is in Java.

Initialize an integer array with size 40

Create a for loop that iterates 40 times. Inside the loop, set the number at index i as i*3

i = 0, numbers[0] = 0 * 3 = 0

i = 1, numbers[1] = 1 * 3 = 3

i = 2, numbers[2] = 2 * 3 = 6

.

.

i = 39, numbers[39] = 39 * 3 = 117

Create another for loop that iterates 40 times and prints the values in the numbers array


Related Questions

Write a program that contains three methods:

Method max (int x, int y, int z) returns the maximum value of three integer values.
Method min (int X, int y, int z) returns the minimum value of three integer values.
Method average (int x, int y, int z) returns the average of three integer values.

Answers

Answer:

#include <stdio.h>//defining header file

int max (int x, int y, int z) //defining a method max that hold three parameters

{

   if(x>=y && x>=z)//defining if block that checks x is greater then y and x is greater then z

   {

       return x;//return the value x

   }

   else if(y>z)//defining else if block it check y is greater then z

   {

       return y;//return the value y

   }

   else//else block

   {

       return z;//return the value z

   }

}

int min (int x, int y, int z) //defining a method max that holds three parameters

{

if(x<=y && x<=z) //defining if block that check x value is less then equal to y and less then equal to z

{

return x;//return the value of x

}

if(y<=x && y<=z) //defining if block that check y value is less then equal to x and less then equal to z

{

return y;//return the value of y

}

if(z<=x && z<=x)//defining if block that check z value is less then equal to x  

{

return z;//return the value of z

}

return x;//return the value of z  

}

int average (int x, int y, int z) //defining average method that take three parameters

{

int avg= (x+y+z)/3;//defining integer variable avg that calculate the average

return avg;//return avg value

}

int main()//defining main method

{

   int x,y,z;//defining integer variable

   printf("Enter first value: ");//print message

   scanf("%d",&x);//input value from the user end

   printf("Enter Second value: ");//print message

   scanf("%d",&y);//input value from the user end

   printf("Enter third value: ");//print message

   scanf("%d",&z);//input value from the user end

   printf("The maximum value is: %d\n", max(x,y,z));//calling the method max

   printf("The minimum value is: %d\n", min(x,y,z));//calling the method min

   printf("The average value is: %d\n", average(x,y,z));//calling the method average

   return 0;

}

Output:

Enter first value: 45

Enter Second value: 35

Enter third value: 10

The maximum value is: 45

The minimum value is: 10

The average value is: 30

Explanation:

In the above-given code, three methods "max, min, and average" is declared that holds three integer variable "x,y, and z" as a parameter and all the method work as their respective name.

In the max method, it uses a conditional statement to find the highest number among them.In the min method, it also uses the conditional statement to find the minimum value from them.In the average method, it defined an integer variable "avg" that holds the average value of the given parameter variable.In the main method, three variable is defined that inputs the value from the user end and passes to the method and print its value.      

Are Dogs are better than video games?

Answers

sometimes bc dogs are very lovey but video games also have there moments

Answer:

In some cases yes.

Explanation:

Some days I really enjoy my video games and other days I enjoy being with my dog but sometimes they are annoying especially if they have way more energy than you

Other Questions
100.0 mL of 4.0C water is heated until its temperature is 37C. If the specific heat of water is 4.18 J/gC, calculate the amount of heat energy needed to cause this rise in temperature. 2. Which of the following inferences about the Founders (authors) of this document is best supported by the following passage (Paragraph 3)?When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume, among the Powers of the earth, the separate and equal station to which the Laws of Nature and of Natures God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.A. The Founders were unsure of their ability to bring about change.B. The Founders had been well-educated at elite universities.C. The Founders were once government officials in Great Britain.D. The Founders believed deeply in the importance of their cause. bruh ur no help its not even a answer dumbo What are some facts about the Great Sphinx? What is one major feature of local governments with a strong mayor-counci structure? O A. The mayor shares power with a city manager. O B. The mayor can pass laws without the council. O C. The mayor has the power to veto council decisions. O D. The mayor has the power of one council member. Translate: I love you a lot.Te amo muchamente.Te amo poco.Te amo muyTe amo mucho. at 6:00 PM its 24F at midnight the temperature was 636F lower than Apple what will the temperature at midnight How do calcium ions help amplify the signal?HELP PLEASE!!! Did the Articles of Confederation have checks and balances? Rob buys 50 feet of border to place around the ceiling of a room. The ceiling is shaped like a square with sides that are 10.8 feet long. How many feet of border will Rob have left? Inflationary pressure in the AS-AD model can be shown as aDemand shock that shifts the AD to the left.rise in input prices affecting most firms across the economy shifting AS curve to the right.rise in input prices affecting most firms across the economy shifting AS curve to the left. Me gusta Choose one season of the year: la primavera, el verano, el otoo o el invierno. Let us know 4 things you like to do in that season.En la primavera, me gusta pasar tiempo en el parque, visitar el zoo con mi familia, fotografiar los tulipanes en Washington y recibir flores de mi esposo.Y a ti que te gusta hacer? How many 1000-Watt lights can be plugged into a standard 120-Volt, 15-Amp outlet? (Hint: W/V=A) * Giving brainiest explain answer Evaluate the following expression. Type your answer as a number.8 + 23 - (4 3) = the 23 is a exponet jus to let you know Which of the following contains the most atoms?24.305 g Mg39.098 gk21.62 g B9.0122 g Be Which type of substance have a definite shape and fixed volume? Solids onlyLiquids and solidsGases onlyLiquids and Gases State whether ancient Greece or ancient Rome had the most developed or best economy, and explain why you chose that civilization. first to answer correctly gets brainleist! I need ya to find the slope for me! Mis padres(sostenerse) con una granja.1Nosotros(irse) del edificio a las cinco.Ella(enfermarse) cuando come hongos.Ellas(maquillarse).Las nias(vestirse) con vestidos color amarillo.Mi padre(ducharse) temprano por la maana.(Ella ducharse)a las ocho de la maana.Ella(vestirse) con un traje.Las mujeres(limarse) las uas.YoKafeitarse) las piernas.Yo(pintarse) los labiosNosotros(sentarse) en el comedor