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
A student should be most cautious using a web address ending in
Inessa [10]

Answer:

It is .com because all the others are school-safe. And .com is snatch-able.

Explanation:

4 0
4 years ago
The _____ is a narrative description of the product, service, or information system.
Sloan [31]
Management support. This fits the best meaning of the description. 
4 0
3 years ago
What describes accenture's approach to automation, both internally as well as for clients?
Molodets [167]
It's approach is to provide custom based services to it's client, mainly through a cloud based system that enable their clients to shift to an automatic system leading to better business operations.
8 0
2 years ago
Which two of the following are conditions of AI programming that enable robots to either accept or reject commands from humans?
inessss [21]
Knowledge and capacity

hope this helps :)
8 0
3 years ago
A disadvantage to using open source software is
yarga [219]

Answer: a higher level of technical skill may be required to install, use, or modify it.

Explanation:

4 0
4 years ago
Other questions:
  • Assume that given , middle and family are three variables of type string that have been assigned values . Write an expression wh
    5·1 answer
  • in cell h5, enter a formula that will calculate the percentage of attendees that went to the Altamonte springs job fair in 2018.
    15·2 answers
  • __________ is the backbone of a computer, connecting all of its components including the central processing unit (CPU) and prima
    5·1 answer
  • What is the advantage of saving a document as a PDF file?
    6·1 answer
  • Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither.
    10·1 answer
  • EdHesive 3.7 Code Practice?
    13·1 answer
  • Discuss your views on multiple backgrounds. What are the advantages and disadvantages of having multiple backgrounds? Your submi
    8·1 answer
  • What can a user modify on a business card using the Edit Business card in the dialog box?​
    8·1 answer
  • A __________ is a sequence of characters.
    10·1 answer
  • Which one of the following careers is the most highly resistant to economic change?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!