17

Java циклы

 2 years ago
source link: https://gist.github.com/Somik-cpp/fc2070bb4a0bec140f41141b44c3308c
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Java циклы · GitHub

Instantly share code, notes, and snippets.

помогите удалить пробел в конце цикла вот задача

На вход подаётся несколько целых чисел. Выведите эти числа, возведённые в степени от двух до пяти.

Формат вывода: для каждого введённого числа степени выводятся в отдельной строке через пробел.

Примечание. Каждая строка вывода оканчивается числом, а не пробелом.

Sample Input:

1 2 3 Sample Output:

1 1 1 1 4 8 16 32 9 27 81 243

вот мой код😉

import java.util.Scanner;

class MyTest { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { if (sc.hasNextInt()) { int n = sc.nextInt(); for (int i = 2; i <= 5; i++) { System.out.printf("%.0f ",Math.pow(n, i)); } System.out.print("\n"); } } } } вывод такой

Failed test #1 of 4. Wrong answer

This is a sample test from the problem statement!

Test input: 1 2 3 Correct output: 1 1 1 1 4 8 16 32 9 27 81 243

Your code output: 1 1 1 1 4 8 16 32 9 27 81 243

как бы ответ правильный, но в конце каждой строки пробел, как его убрать?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK