Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package practika2;
- import java.util.Scanner;
- public class num2 {
- public static void main (String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.println("Введите натуральное число N: ");
- int N = in.nextInt();
- System.out.println("Введите число(кол-во последних цифр) m: ");
- int m = in.nextInt();
- int sum = 0;
- for (int i = 0; i < m; i++) {
- sum+= N % 10;
- N = N / 10;
- }
- System.out.println("Сумма m последних чисел : " + sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement