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
frutty [35]
3 years ago
12

The following 2D array has been created:

Computers and Technology
2 answers:
Airida [17]3 years ago
4 0

Answer:

public class Main

{

public static void main(String[] args) {

 

 int [][] a = new int[4][5];

 

 a[0][0] = 1;

 a[0][1] = 2;

 a[0][2] = 3;

 a[0][3] = 4;

 a[0][4] = 5;

 a[1][0] = 10;

 a[1][1] = 9;

 a[1][2] = 8;

 a[1][3] = 7;

 a[1][4] = 6;

 a[2][0] = 11;

 a[2][1] = 12;

 a[2][2] = 13;

 a[2][3] = 14;

 a[2][4] = 15;

 a[3][0] = 20;

 a[3][1] = 19;

 a[3][2] = 18;

 a[3][3] = 17;

 a[3][4] = 16;

 

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

     for (int j = 0; j < 5; j++){

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

     }

     System.out.print("\n");

 }

}

}

Explanation:

  • Inside the main method, initialize the 2D array with their respective values at the appropriate indexes.
  • Iterate over the 2D array using a nested For loop.
  • The outer loop iterates over the rows, while the inner loop iterates over the columns of the 2D array respectively.
  • Finally inside the nested For loop, print the value of 2D array using the i and j index.

Output:

1 2 3 4 5

10 9 8 7 6

11 12 13 14 15

20 19 18 17 16

RSB [31]3 years ago
3 0

Answer:

I wrote this program using C# and Visual Studio. This program requires to display 2D array which has 4 rows and 5 columns. it is also noted that, this program requires to display first and third row in ascending order while second and fourth row in descending order.

To iterate through each row for loop is used and inside for loop, switch statement is used to decide on first, second, third and fourth row that is which rows should be displayed in ascending orders, and which are required to display in descending orders.

Explanation:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace _2D_Array

{

   class Program

   {

       static void Main(string[] args)

       {

           int[,] a = new int[4, 5]{

                              {1, 2, 3,4,5} ,   /*  initializers for row indexed by 0 */

            {6, 7,8,9,10} ,   /*  initializers for row indexed by 1 */

          {11,12,13,14,15},/*  initializers for row indexed by 2 */

                              { 16,17,18,19,20},/*  initializers for row indexed by 3 */

           };

           for (int row = 0; row < 4; row++)// here we iterate through each row and display the result

           {

               switch (row)//the purpose of using switch statement  is that, we will display first and 3rd row in ascending order while 2nd and 5th row in descending order

               {

                   case 0:// here to display row 1

                       {

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

                           {

                               Console.Write("[");

                               for (int j = 0; j < 5; j++)

                                   Console.Write(a[i, j]+ (j >3 ? "" : ","));

                           }

                           Console.Write("]");

                           Console.WriteLine();

                           

                       }

                       break;

                   case 1://here to display row two

                       {

                           for (int i = 1; i < 2; i++)

                           {

                               //Console.WriteLine("row 1");

                               Console.Write("[");

                               for (int j = 4; j >= 0; j--)// to display array elements in reverse order

                               {

                                   Console.Write(a[i, j] + (j == 0 ? "" : ","));

                               }

                           }

                           Console.Write("]");

                           Console.ReadLine();

                           break;

                       }

                   case 2://here to display the 3rd row

                       {

                           for (int i = 2; i < 3; i++)

                           {

                               Console.Write("[");

                               for (int j = 0; j <5; j++)

                               {

                                   Console.Write(a[i, j] + (j > 3 ? "" : ","));

                               }

                           }

                           Console.Write("]");

                           Console.ReadLine();  

                       }

                       break;

                   case 3://here to display 4th row.  

                       {

                           for (int i = 3; i < 4; i++)

                           {

                               //Console.WriteLine("row 1");

                               Console.Write("[");

                               for (int j = 4; j >= 0; j--)

                               {

                                   Console.Write(a[i, j] + (j == 0 ? "" : ","));

                               }

                               Console.Write("]");

                           }

                           Console.ReadLine();

                       }

                       break;

               }

           }

       }

   }

}

You might be interested in
In what ways do you think the media should function in a democratic society?
insens350 [35]

Answer:

i think it should slow down

Explanation:

i think this because people are always on social media so they should put down their devices and interact with others and sometimes they are violent on their devices so it would be better if people did stay off their devices for a little bit.

7 0
3 years ago
I'm trying to export a video with HitFilm Express, I am either unable to click the export button or it gets to 43% and just stop
fiasKO [112]

Answer:

Yea I am also confused oof

8 0
2 years ago
¿que lenguaje de programacion usan los operadores matematicos?​
kolbaska11 [484]

Answer:

Matlab / GNU Octave. MATLAB (laboratorio de matrices) es un entorno informático numérico multiparadigma y un lenguaje de programación de cuarta generación.

Explanation:

8 0
3 years ago
Read 2 more answers
A(n) __________ is a common list operation used in programming. Its purpose is to iterate through a list of items, one item at a
34kurt
Linear search

You implement this algorithm by iterating over each item, and checking if the item matches what you are searching for.

It is linear because it takes a linear amount of time to search for an item.
5 0
2 years ago
____ are diagrams used in mathematics and logic to help describe the truth of an entire expression based on the truth of its par
Bad White [126]
<span>Truth tables are diagrams used in mathematics and logic to help describe the truth of an entire expression based on the truth of its parts.

A truth table shows all the possible combinations (outputs) that can be produced from the given inputs. They are mainly used in Boolean algebra.</span>
4 0
2 years ago
Other questions:
  • Every preprocessing directive must begin with:
    11·1 answer
  • ____ data exist in a format that does not lend itself to processing that yields information.
    8·1 answer
  • How can you best protect yourself when using social media
    5·2 answers
  • Which javascript method should you use if you want to specify a message string to appear on your web page as it loads?
    13·1 answer
  • Which of the following statements about electronic cover letters is true?
    14·2 answers
  • How many pieces are there in a normal laptop??? Good luck and solve carefully
    9·1 answer
  • Java supports ________; collections of related methods that typically enable you to tell objects what to do, but not how to do i
    12·1 answer
  • Which of the following is true of binary files?
    6·2 answers
  • What are the concerns surrounding 5G cellular networks?​
    6·1 answer
  • David is taking a test. To answer a question, he first covers up the answer choices. Next, he tries to answer the question. Then
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!