Advertisement
kidroca

Divisible by 3

Nov 27th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5. import java.util.stream.Collectors;
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args) {
  10.  
  11.         Scanner console = new Scanner(System.in);
  12.  
  13.         int n = Integer.parseInt(console.nextLine());
  14.         int current = 3;
  15.         ArrayList<Integer> list = new ArrayList<>();
  16.  
  17.         for (int i = n; i > 0; i--) {
  18.             list.add(current);
  19.             current += 3;
  20.         }
  21.  
  22.         System.out.println(
  23.                 list.stream()
  24.                     .map(Object::toString)
  25.                     .collect(Collectors.joining(", ")));
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement