1
I have this sequence of numbers: 7, 14, 21, 28, 35, 42, 49
, may have more or less numbers.
I need to add them all up as follows:
7+7=14
14+7=21
21+7=28
28+7=35
35+7=42
42+7=49
49+7=56
That was 7, the others are missing. All + 14, all + 21, all + 28, so on...
Example:
7=(14,21,28,35,42,49,56)
14=(21,28,35,42,49,56,63)
21=(28,35,42,49,56,63,70)
28=(35,42,49,56,63,70,77)
35=(42,49,56,63,70,77,84)
42=(49,56,63,70,77,84,91)
49=(56,63,70,77,84,91,98)
These are the results of each sum of all numbers, and the number that appeared the most times is the "56" ie:
7+49=56
14+42=56
21+35=56
28+28=56
35+21=56
42+12=56
49+7=56
I need to print these results in lists and check the number of numbers to get the number that appears most in the results..
Imprimir Resultados:
7=(14,21,28,35,42,49,56)
14=(21,28,35,42,49,56,63)
21=(28,35,42,49,56,63,70)
28=(35,42,49,56,63,70,77)
35=(42,49,56,63,70,77,84)
42=(49,56,63,70,77,84,91)
49=(56,63,70,77,84,91,98)
Print Verification of quantity:
14=1
21=2
28=3
35=4
42=5
49=6
56=7*
63=6
70=5
77=4
84=3
91=2
98=1
Print Final Result:
The sum with the highest result is the number "56".
I tried this code, but it’s not working:
public static void main(String[] args) {
for (long a=1; a <= 7; a++) {
long z;
z=a*7;
for (long x = z; x <= z; x++) {
long y;
y=z+x;
System.out.println(x+"="+y);
}
}
}
}
Exit from the program:
The output of the program would have to come out like this:
Lists:
7=(14,21,28,35,42,49,56)
14=(21,28,35,42,49,56,63)
21=(28,35,42,49,56,63,70)
28=(35,42,49,56,63,70,77)
35=(42,49,56,63,70,77,84)
42=(49,56,63,70,77,84,91)
49=(56,63,70,77,84,91,98)
Checking:
14=1
21=2
28=3
35=4
42=5
49=6
56=7*
63=6
70=5
77=4
84=3
91=2
98=1
Upshot:
56*
UPDATING
My program sums up all the numbers of a given "sequence" with the sequence of numbers itself, and prints out a list of the results of each of them. The implementation of the program would be the verification of the results of all sums, ie, verify the amount of each result and print the amount of times that this result was obtained, thus determining, which was the result that appeared most times.
The program is divided into 3 Steps:
- Lists
- Checks
- Upshot
The 1st Stage is completed:
Established sequence: 7,14,21,28,35,42,49
.
1)Lists
7=(14,21,28,35,42,49,56)
14=(21,28,35,42,49,56,63)
21=(28,35,42,49,56,63,70)
28=(35,42,49,56,63,70,77)
35=(42,49,56,63,70,77,84)
42=(49,56,63,70,77,84,91)
49=(56,63,70,77,84,91,98)
Already in the 2nd Stage I’m having some difficulties, I’m not getting to pass the Lista
who is in Integer
for int
, an error occurs in this conversion and the check does not work.
In the program in check[z]++;
was meant to be check[lista]++;
I left the z
which are just the sequence numbers, (7,14,21,28,35,42,49) just as an example, because I can’t get the conversion to work the verification.
Program:
package etapa2;
import java.util.ArrayList;
import java.util.List;
public class Etapa2 {
private List<Integer> lista = null;
public Etapa2(List<Integer> lista) {
this.lista = lista;
}
public void soma() {
for (Integer externo : lista) {
System.out.print(externo + "=");
List<String> resultado = new ArrayList<String>();
for (Integer interno : lista) {
resultado.add(String.valueOf(interno + externo));
}
System.out.println("("+String.join(",", resultado)+")");
}
}
public static void main(String args[]) {
List<Integer> lista = new ArrayList<>();
int[] check = new int[100000000];
for (int f=1; f<=7; f++){
int z,p;
z=f*7;
lista.add(z);
check[z]++;
}
Etapa2 sl = new Etapa2(lista);
sl.soma();
System.out.println("------------");
int maior = 0;
for (int i : check) {
if (i > maior) maior = i;
}
for (int j = 0; j <= 1000000; j++) {
if (check[j] == 0) continue;
System.out.println(j + "=" + check[j] + (check[j] == maior ? "*" : ""));
}
}
}
Exit:
We saw that the 2nd Step is wrong, because the "list" is not placed to be checked, but the numbers of the sequence just as an example.
With the List at check (check[list]++;) the output of the program should be like this:
7=(14,21,28,35,42,49,56)
14=(21,28,35,42,49,56,63)
21=(28,35,42,49,56,63,70)
28=(35,42,49,56,63,70,77)
35=(42,49,56,63,70,77,84)
42=(49,56,63,70,77,84,91)
49=(56,63,70,77,84,91,98)
14=1
21=2
28=3
35=4
42=5
49=6
56=7*
63=6
70=5
77=4
84=3
91=2
98=1
And the Final Step, put the result that appeared more often, in highlight and print the number:
Resultado Vencedor = 56*
I don’t understand what problem you’re trying to solve. I see it has to do with the multiplication table of 7 and the sum of digits, but I didn’t understand your statement.
– Victor Stafusa
Hello, Felipe. Welcome to [en.so]! Look, I confess I read it twice and I still don’t understand the goal. As far as I can ascertain, this is precisely the central problem here, that is, it is not a question of code, but of defining the problem correctly. This is something fundamental to programming: solve the problem first, then code. No problem defined, there is no way to define an algorithm and implement it correctly.
– utluiz
That said, I actually think you can understand, but the example with the sequence of multiples of 7 leads to understand that it is a simple arithmetic progression. What you really want is a square matrix whose rows and columns are the list numbers and the elements are the sum of the row and column number. Then you want to take the most common element. I see several mathematical applications of this, although I’m too rusty to remember the exact terminology.
– utluiz