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
Lydia used software to calculate the budget for each department. To create this budget, she used a _____.
Ann [662]
Lydia used software to calculate the budget for each department. To create this budget, she used a spreadsheet.
4 0
3 years ago
Read 2 more answers
.WAP to enter monthly sale of Salesman and give him commission i.E. If the monthly sale is more than 500000 then commision will
nexus9112 [7]

sales = float(input("Enter monthly sales amount: $"))

commission = 0.05

if sales> 500000:

   commission = 0.1

print("You earned: $"+str(sales*commission))

I wrote my code in python 3.8. I hope this helps.

5 0
3 years ago
A*=++a/6+b++ 3 if a=3,b=4​
Vinil7 [7]

Answer:

a=22.5

Explanation:

Given

a*=++a/6+b++3

Required

The result when a=3 and b=4

Analyzing the given instruction

a*=(++a)/(6)+(b++3)

Single out and solve the expressions in bracket

(++a) = a -- When the ++ operator appears before an operand, it is called pre increment. meaning that the operation will be done before the operand will be incremented.

So: in this case: ++a = a

b++3 = b + 3

The operator, as used in that statement is the same as: b + 3.

So:

a*=(++a)/(6)+(b++3)

a*=(a)/(6)+(b+3)

a*=(3)/(6)+(4+3)

a*=0.5+7

a*=7.5

The above expression is calculated as:

a=a*7.5

So:

a=3*7.5

a=22.5

8 0
3 years ago
Formulas should follow the___
tatuchka [14]

Answer:

Order of operations

Explanation:

4 0
2 years ago
Which of the following ensures that dropped packets are resent?
Agata [3.3K]

Answer:

TCP

Explanation:

Transmission control protocol ensures packets loss and performs retransmission

TCP works with Internet Protocol (IP)

TCP/IP defines how computers send data packets to each other.

TCP allows transmission of information in both the direction.

Bit rate :defines the rate at which bits are transferred from one place to another

7 0
3 years ago
Other questions:
  • What view and zoom setting do you need for true WYSIWYG display? Why?
    14·1 answer
  • Explain the term remote backup with examples.​
    5·1 answer
  • Scientific models can be used for a variety of different purposes. Which of the following statements about scientific models is
    7·2 answers
  • Write a program with a function that accepts a string as an argument and returns a copy of the string with the first character o
    11·1 answer
  • Line spacing refers to the amount of space between each line in a paragraph. A. True B. False
    14·2 answers
  • Which statement reflects an opinion about technology? Select all that apply. Select one or more: a. It is easy to imagine that a
    5·1 answer
  • A fast way to add up a column of numbers is to click in the cell below the numbers and then: Click Subtotals on the Data menu. V
    6·2 answers
  • What is an outcome in a game? Don't search google just give me an answer
    9·1 answer
  • What is Data rate?<br> What is BAUD RATE?<br> What is bandwidth?
    8·1 answer
  • Describe the specific job you would want to have if you were going to pursue a career in digital music or video.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!