Skip to content

Instantly share code, notes, and snippets.

@i0nyx
Created December 13, 2016 13:54
Show Gist options
  • Save i0nyx/1c002e1a76ff3771077d8d0e741d17d4 to your computer and use it in GitHub Desktop.
Save i0nyx/1c002e1a76ff3771077d8d0e741d17d4 to your computer and use it in GitHub Desktop.
Glava 1
/*
Найти сумму всех n-значных чисел, кратных k (1 ≤ n ≤ 4).
*/
package gl_1.zadanie_gl_1;
import java.util.Scanner;
public class N_6 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int a=0,b=0,c=0,n=0,sum,k=0;
Scanner sc = new Scanner(System.in);
System.out.println("Введите число k:");
if(sc.hasNextInt()){
k = sc.nextInt();
}
for(int i = 0; i <= 9; i++){
if(i % k == 0){
a += i;
}
}
for(int i = 0; i <= 99; i++){
if(i % k == 0){
b += i;
}
}
for(int i = 0; i <= 999; i++){
if(i % k == 0){
c += i;
}
}
for(int i = 0; i <=9999; i++){
if(i % k == 0){
n += i;
}
}
sum = a + b + c + n;
System.out.println(sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment