Answer the question
In order to leave comments, you need to log in
Why doesn't java code a^b work?
Hello.
Please tell me what am I doing wrong?
There is a task, write a method that takes 2 integers greater than zero and must return an integer in which the first number is raised to the power of the second.
I do it like this
import java.util.Scanner;
public class testing {
public static void main(String[] args) {
System.out.print("Введи число (а): ");
Scanner get_input = new Scanner(System.in);
int a = 0;
while (!get_input.hasNextInt() || ((get_input.nextInt()) <= 0)) {
System.out.print("Введи число больше 0: ");
get_input.next();
}
a = get_input.nextInt();
System.out.print("Введи число (b): ");
int b = 0;
while (!get_input.hasNextInt()) {
System.out.print("Введи число больше 0: ");
get_input.next();
}
b = get_input.nextInt();
int c = getDegree(a, b);
System.out.println("'A' в степени 'B' = " + c);
}
public static int getDegree(int a, int b) {
int res = (int) Math.pow(a, b);
return res;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question