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]
2 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]2 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 is a mini computer and what are it’s typical applications?
Molodets [167]

Answer:

it is a computer of medium power more than a microcomputer but less than a.minuframe

3 0
2 years ago
Read 2 more answers
How does an author use artifacts in literature?
cestrela7 [59]
They use artifacts in l<span>iterature in order to develop the plot and the characters.</span>
7 0
3 years ago
Groups to which we belong are defined late in our development true or false
Anna71 [15]
The answer is false......
7 0
3 years ago
As a result of the Internet, people today
Nimfa-mama [501]

Answer:

hi there, the answer is

a. use more mobile devices

hope this helps :)

have a good day!

Explanation:

i just took the quiz rnnn

3 0
3 years ago
Read 2 more answers
How is the internet being used by people to communicate?
Tasya [4]

cuz people talk to others on fb ,sc and other stuff like that hope this helps

7 0
3 years ago
Other questions:
  • You are given a string of n characters s[1 : : : n], which you believe to be a corrupted text document in which all punctuation
    12·1 answer
  • You've been asked to find the average of a range of numbers. Which of the following could you use to find the average of cells A
    9·1 answer
  • Which are examples of copyrighted online materials? Check all that apply.
    14·2 answers
  • A building is equipped with light sensors that turn off the fluorescent lights when natural light is above a certain brightness.
    5·1 answer
  • What’s bigger 4,000,000 KB or 2.8 GB
    5·2 answers
  • Which of the following statements is NOT a valid way to create a date object named birthday?
    13·1 answer
  • Match the term to its correct defintion
    6·1 answer
  • 4.9 Code Practice: Question 4
    10·1 answer
  • You are given a graph G = (V, E) with positive edge weights, and a minimum spanning tree T = (V, E’) with respect to these weigh
    14·1 answer
  • When right-clicking an object, a ____ menu appears, which contains frequently used commands related to the object.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!