import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int count = input.nextInt();
for(int i = 1 ; i <= count; i++ ) {
System.out.print( i + " ");
for(int j = 1; j <= i; j++) {
System.out.print( i + " ");
}
}
}
}
Write a program that prints a part of the sequence 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 ... (the number is repeated as many times, to what it equals to). The input to the program is a positive integer n: the number of the elements of the sequence the program should print. Output the sequence of numbers, written in a single line, space-separated.
For example, if n = 7, then the program should output 1 2 2 3 3 3 4.
Jake
9 уровень
Задача: n цифра введена в сканнер, далее нужно вывести n количество цифр. Как это сделать?
Обсуждается
Комментарии (2)
- популярные
- новые
- старые
Для того, чтобы оставить комментарий Вы должны авторизоваться
Павел Безумный учёный Expert
28 мая 2020, 18:11
Можно ввести переменную-счётчик для подсчёта напечатанных в консоль чисел:
Перед тем, как вывести очередное число в консоль, значение переменной numCounter увеличивается на 1. Когда это значение превысит заданное пользователем count, все последующие числа до конца работы обоих циклов выводиться не будут.
+1
JakeAndroid Developer в Яндекс
28 мая 2020, 18:22
Спасибо!
0