Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package myApp;
- import java.util.Scanner;
- public class class03_ex06 {
- public static void main(String[] args) {
- //init vars
- int n = 0;
- //usage msg
- System.out.println("Integer: ");
- //open in_Stream, parse & close
- Scanner s = new Scanner(System.in);
- n = s.nextInt();
- s.close();
- //loop n times
- for (int i=1; i<=n; i+=1) {
- int sum = 0; //hold sum of digits
- //calculate sum of digits using recursion
- for (int j=i; j>0; ) {
- sum += j%10; //add right digit to sum
- j /= 10; //remove right digit from the current iteretaion's number
- }
- //check myself
- //System.out.printf("sum %d: %d%n", i, sum);
- //output only numbers that match the pattern
- if (i%3==0 && sum<5) {
- System.out.println(i);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment