subject

Write a piece of code that constructs a jagged two-dimensional array of integers named jagged with five rows and an increasing number 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

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:40
Mariah was working on a multimedia presentation that included both video and audio files. the file was huge, and she wanted to send it to her coworker in another office. she needed to reduce the size of the file so that it could be transmitted faster. the utility she used to do this was
Answers: 2
question
Computers and Technology, 23.06.2019 03:00
State 7 common key's for every keyboard
Answers: 1
question
Computers and Technology, 23.06.2019 09:00
Which best describes the role or restriction enzymes in the analysis of edna a. to break dna into fragments that vary in size so they can be sorted and analyzed b. to amplify small amounts of dna and generate large amounts of dna for analysis c. to purify samples of dna obtained from the environment so they can be analyzed d. to sort different sizes of dna fragments into a banding pattern that can be analyzed
Answers: 1
question
Computers and Technology, 24.06.2019 00:00
Visualizing a game of “tag” to remember the meaning of contagious
Answers: 3
You know the right answer?
Write a piece of code that constructs a jagged two-dimensional array of integers named jagged with f...
Questions
question
Mathematics, 15.12.2019 21:31
question
Computers and Technology, 15.12.2019 21:31
question
English, 15.12.2019 21:31
question
Social Studies, 15.12.2019 21:31
Questions on the website: 13722359