Created
December 13, 2016 13:51
-
-
Save i0nyx/3f3643f0468d047d9d773b7079a92c57 to your computer and use it in GitHub Desktop.
Glava 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Найти сумму всех n-значных чисел (1 ≤ n ≤ 4). | |
*/ | |
package gl_1.zadanie_gl_1; | |
public class N_5 { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
int i, n = 0, a = 0, b = 0, c = 0, sum; | |
for(i = 0; i <= 9; i++){ | |
n += i; | |
} | |
for(i = 0; i <= 99; i++){ | |
a +=i; | |
} | |
for(i = 0; i <= 999; i++){ | |
b += i; | |
} | |
for(i = 0; i <= 9999; i++){ | |
c += i; | |
} | |
sum = a + b; | |
System.out.println(sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
вариант решения, способный принимать граничные значения числа n: summa(1, 4) посчитает сумму всех n-значных чисел (1 ≤ n ≤ 4)
вроде по условию нужно получить сумму 0-9999. У тебя на выходе sum = 0-999
public static long summa(int a, int b)
{
long res = 0;