This is a program that verifies between 1 to 100 which numbers are divisible by 3 and also counts their quantity, all over this formula:
a=n*n;
b=a+?;
This question is where I wanted to loop for any number from 1 to 100.
Code:
public static void main(String[] args) {
List<Long> Lista1 = new ArrayList();
for (long n = 1; n <= 100; n++) {
long a,b;
a = n*n;
b = a+2;
if((b % 3) == 0) {
Lista1.add(b);
}
}
System.out.println("Quantidade Números: "+Lista1.size());
System.out.println("Divisível por 3: "+Lista1);
}
}
Icannotloopin"b".
b = a+2;
is equal to 67 numbers ...
If you change:
b = a+3;
is equal to 33 numbers .. (quantity)
Changed, ie, would need a Print, with a list of 1 to 100 of all quantities as the formula is changed (if you can change the sum of this formula with a loop).
% with% being% with%. No number from 1 to 100 is divisible by 3.
Now if you have made a list, from 1 to 3 of this "formula with loop".
result:
1 = 0
2 = 67
3 = 33
that is ...
b = a+1; = 0
b = a+2; = 67
b = a+3; = 33
for a better understanding:
a = n * n; = number x number = 1 * 1 = 1
b = a + 2; = 1 + 2 = 3
a = n * n; = number x number = 2 * 2 = 4
b = a + 2; = 4 + 2 = 5
a = n * n; = number x number = 57 * 57 = 3249
b = a + 2; = 3249 + 2 = 3251
Answer was resolved Thanks!