Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- for (int i = 1; i <= n; i++) {
- int sum = 0,
- number = i;
- for (int j = 0; j < Integer.toString(i).length(); j++) {
- sum += number % 10;
- number /= 10;
- }
- if (sum == 5 || sum == 7 || sum == 11) {
- System.out.printf("%d -> True\n", i);
- } else {
- System.out.printf("%d -> False\n", i);
- }
- }
- }
- }
- OR:
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine()),
- number, sum;
- for (int i = 1; i <= n; i++) {
- sum = 0;
- number = i;
- while (number > 0) {
- sum += number % 10;
- number /= 10;
- }
- System.out.printf("%d -> %s\n", i, (sum == 5 || sum == 7 || sum == 11) ? "True" : "False");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement