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
Device that converts sound into electrical signals, which are sent to the computer or other recording device
belka [17]
<span>D.sound card is the Answer</span>
3 0
3 years ago
This program will output a right triangle based on user specified height triangle_height and symbol triangle_char. (1) The given
Arturiano [62]

Answer:

See explaination

Explanation:

triangle_char = input('Enter a character:\n')

triangle_height = int(input('Enter triangle height:\n'))

print('')

for i in range(triangle_height):

for j in range(i+1):

print(triangle_char, end = " ")

print()

4 0
3 years ago
What websites can help you learn about general career treads
Tcecarenko [31]
Hi!

The Bureau of Labour Statistics is a government site which is specifically made just for this purpose.

By using it, you have access to thousands of jobs with tons of great factual information. 

Hopefully, this helps! =)
6 0
3 years ago
________ was one of the first uses of the Internet
NeTakaya

Government weapon in cold war

3 0
3 years ago
Read 2 more answers
HELP PLZZ WILL MARK BRAINLIEST
adoni [48]

Answer:

if you could capture another image of this work bc I cant make out some words I can barley make out words

4 0
3 years ago
Other questions:
  • You use_____ to view an XPS file
    10·1 answer
  • Write the execution steps if the input is a lion.
    11·1 answer
  • What are the key goal, performance, and risk indicators?
    15·1 answer
  • What is constructive criticism?
    5·1 answer
  • Going to Grad School! In the College of Computing and Software Engineering, we have an option for students to "FastTrack" their
    11·1 answer
  • Methods that require you to use an object to call them are called ____ methods.1. accessor
    7·1 answer
  • Match each type of software license with the appropriate definition.
    11·1 answer
  • Question 2 (1 point)
    8·1 answer
  • Help with this quiz question thank you!
    12·2 answers
  • What are the 5 font/typography families
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!