


Возведение в степень. Java.
Добрый вечер. Хелп.
[a..b]
нужно каждое число возвести в квадрат и вывести на экран
Пример:
а = 3
б = 5
результ:
9
16
25
Спасибо.
¯\_ツ_/¯
import java.util.Scanner;
import java.lang.System;
public class MathDemo {
public static void main(String[] args) {
System.out.println("Введите число");
Scanner x= new Scanner(System.in);
// get two double numbers
int xch = x.nextInt();
System.out.println("Введите степень");
int ystep = x.nextInt();
x.close();
// print x raised by y and then y raised by x
System.out.println( + xch + " в степени " + ystep + " ="
+ Math.pow(xch, ystep));
}
}
//здесь числои степень вводятся с клавы
Например так:
import java.lang.*;
public class MathDemo {
public static void main(String[] args) {
// get two double numbers
int x = 3;
int y = 2;
// print x raised by y and then y raised by x
System.out.println("Math.pow(" + x + "," + y + ")=" + Math.pow(x, y));
System.out.println("Math.pow(" + y + "," + x + ")=" + Math.pow(y, x));
}
}