Reputation: 1
I am a university student and I have an introductory course in Java programming in financial management, and as having no knowledge with Java, I appeal to your expertise in this area to help me solve this little exercise. The statement number 3 see below, I do not know how to create the second table (called Table 2), how do I increment a second table.
We have the following integer array of size 7:
25 10 45 34 3 56 78
1) Create the table in your Java program and display it on the screen; (fine)
2) Sort the table and display the result on screen; (fine)
3) Create another table (Table 2 that the call in the following) that contains the same values as the above table but that is of size 10; (dont get it)
4) Fill the empty boxes of new avecl has value 1. Table 2
5) Sort Table 2 in ascending order and display the result on screen. (Fine)
Here's what I've done so far.
package com.company;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
System.out.println("Nombre Entiers pour Tableau 1");
int nombreEntiers = 7;
int [] tableau = {25, 10, 45, 34, 3, 56, 78};
System.out.println(Arrays.toString(tableau));
System.out.println("Nombre Entiers pour Tableau 2");
int[] tableau2 = new int [10];
tableau2[0] = 1;
tableau2[1] = 1;
tableau2[2] = 1;
tableau2[3] = 3;
tableau2[4] = 10;
tableau2[5] = 25;
tableau2[6] = 34;
tableau2[7] = 45;
tableau2[8] = 56;
tableau2[9] = 78;
System.out.print(Arrays.toString(tableau2));
}
}
Sorry is in french. - Nombre entiers = intenger in french - Tableau = table in french
Thank you World!
Upvotes: 0
Views: 60
Reputation: 1683
You could use a for loop to put the values from tableau
into tableau2
like this:
for (int i = 0; i< tableau.length; i++) {
tableau2[i] = tableau[i];
}
Then you will have tableau2
with all the tableau
values with three 0 values at the end.
You can read on For loop here.
Also, don't sort it manually. Use Arrays sort
Usage: Arrays.sort(tableau2)
this will sort you array.
Upvotes: 1