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
Which Packet Tracer feature do you think will be most helpful for you in learning how to manage a network
Norma-Jean [14]

Answer:

Its ability to sniff and analyze packets in a network.

Explanation:

Network administrators require advanced skills and tools to manage a large network, to analyze packets as they are transmitted across the network.

Packet tracer helps to monitor the network connection and packet transfer. It informs the administrator of a dropped connection, slow transmission due to a bottle-neck, and many more packet related issues

7 0
2 years ago
I WILL GIVE BRAINLIEST TO WHO ANSWERS FIRST AND CORRECTLY.
svlad2 [7]

Answer:

The answer is false

Explanation:

Please give me brainliest so I can post my artwork

6 0
3 years ago
Write a c program using loops to generate following output.
Keith_Richards [23]

Answer:

#include <stdio.h>

int main()

{

for (int n = 12; n > 0; n--) {

 printf("%d x 2 = %d\n", n, n * 2);

}

}

Explanation:

Only one loop.

8 0
2 years ago
Good Morning! Please Help!
vova2212 [387]

Answer:

cyber bullying

rights

technology

speech

education

study

issues

Explanation:

4 0
3 years ago
How can i become an ailen?
DIA [1.3K]
Go to a different state as a migrant and then your a alien
8 0
3 years ago
Read 2 more answers
Other questions:
  • What of the following google tools support collaboration
    10·1 answer
  • Differentiate between third and fourth generation of computer​
    6·1 answer
  • Which of the following payment types require you to pay upfront A. Money order and credit card B. Money orders and prepaid card
    9·2 answers
  • How can you keep your files organized on your computer?
    13·2 answers
  • The ____________ mechanism consists of a lever arm attached to the mousetrap spring.
    15·1 answer
  • Henry conducted a survey on an ad done by his company. In the survey, he asked people to evaluate the ad and state whether they
    8·1 answer
  • Given the three thread states: running, runnable (i.e., ready), and blocked (i.e., waiting), state which of the six possible thr
    13·1 answer
  • Gray London is a retired race car driver who helped Dale Earnhardt, Jr. get his start. He is writing a book and making a video a
    9·1 answer
  • What is a key differentiator of Conversational Artificial Intelligence (AI)
    11·1 answer
  • Organizations can face criminal or civil penalties for being ______ in protecting their sensitive data.
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!