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
Harman [31]
3 years ago
10

Write a piece of code that constructs a jagged two-dimensional array of integers named jagged with five rows and an increasing n

umber of columns in each row, such that the first row has one column, the second row has two, the third has three, and so on. The array elements should have increasing values in top-to-bottom, left-to-right order (also called row-major order). In other words, the array's contents should be the following: 1 2, 3 4, 5, 6 7, 8, 9, 10 11, 12, 13, 14, 15
PROPER OUTPUT: jagged = [[1], [2, 3], [4, 5, 6], [7, 8, 9, 10], [11, 12, 13, 14, 15]]
INCORRECT CODE:
int jagged[][] = new int[5][];
for(int i=0; i<5; i++){
jagged[i] = new int[i+1]; // creating number of columns based on current value
for(int j=0, k=i+1; j jagged[i][j] = k;
}
}
System.out.println("Jagged Array elements are: ");
for(int i=0; i for(int j=0; j System.out.print(jagged[i][j]+" ");
}
System.out.println();
}
expected output:jagged = [[1], [2, 3], [4, 5, 6], [7, 8, 9, 10], [11, 12, 13, 14, 15]]
current output:
Jagged Array elements are:
1
2 3
3 4 5
....
Computers and Technology
1 answer:
Ksivusya [100]3 years ago
4 0

Answer:

Explanation:

The following code is written in Java and it uses nested for loops to create the array elements and then the same for loops in order to print out the elements in a pyramid-like format as shown in the question. The output of the code can be seen in the attached image below.

class Brainly {

   public static void main(String[] args) {

       int jagged[][] = new int[5][];

       int element = 1;

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

           jagged[i] = new int[i+1]; // creating number of columns based on current value

           for(int x = 0; x < jagged[i].length; x++) {

               jagged[i][x] = element;

               element += 1;

           }

       }

       System.out.println("Jagged Array elements are: ");

       for ( int[] x : jagged) {

           for (int y : x) {

               System.out.print(y + " ");

           }

           System.out.println(' ');

       }

       }

   }

You might be interested in
What do you use for soaking hands and holding soapy water​
sertanlavr [38]

Answer

???

Explanation:

Was this a school question?

5 0
3 years ago
Read 2 more answers
Suppose one hundred stores participated in the
Sindrei [870]
I think the answer is A
7 0
4 years ago
All of the information on the Internet has been verified and is factual. <br> a. True<br> b. False
Hitman42 [59]
False because someone could lie on the internet to imoress someone
5 0
4 years ago
Read 2 more answers
Before inserting a cover page or a blank page, where should the cursor be placed?
sp2606 [1]

Answer:

At the beginning of the first line on a page to insert the new page before.

Explanation:

if you need more assistance please let me know.

cheers

8 0
3 years ago
Read 2 more answers
ASAP!!!<br><br> How do you follow a podcast?
11111nata11111 [884]
You go to the podcast link and you press follow or subscribe
3 0
3 years ago
Other questions:
  • Which is a form of malware? A. clickjacking B. spam C. cookies D. Trojan horse
    7·2 answers
  • When using the strcat function, you must be careful not to overwrite the bounds of an array?
    5·1 answer
  • _______ tags are tiny chips that can be embedded into almost anything and contain information used to track and locate lost pets
    14·1 answer
  • Given two 3x3 arrays of integer, x1 and x2, write the code needed to copy every value from x1 to its corresponding element in x2
    6·1 answer
  • While you work on the customer’s printer, he continues chatting about his network and problems he’s been experiencing. One compl
    14·2 answers
  • Use Python.
    7·1 answer
  • Hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
    14·2 answers
  • Periodic Table Question 2:
    9·1 answer
  • Can you adopt me in the orphanage u saw Tammy after school?
    7·1 answer
  • It displays the contents of the active cell. It allows you to enter and edit data, such as formulas.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!