Reputation: 1
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++)
{
double a=sc.nextInt();
double b=sc.nextInt();
double n=sc.nextInt();
double result=0;
for(int j=0;j<n;j++)
{
double power;
double m;
power = Math.pow(double m, double n);
double result = result+power*b;
System.out.println(result);
}
}
the compiler says .class is required in the statement " power = Math.pow(double m, double n);
"
what did i miss in that statement...thank you
Upvotes: 0
Views: 503
Reputation: 863
There are different errors or mistakes in your code. I will go through them from top to bottom.
Your variable a
is never used. You could delete the whole double a=sc.nextInt();
line without affecting your program
Your variable m
is not initialized and has no value when you use it the first time
When calling a method you don't specify the data types. The data types will be taken from the variables you pass into that method. So there could be methods with the same name but with different data types in their parameter list. Imagine a method int sum(int a, int b)
taking the parameters a
and b
that have to be of integer type. You can easily imagine, that there may be a situation where you don't want to sum integers but doubles. So you could look out for a method double sum (double a, double b)
and you could use this method just like the first one but this time for variables/literals of double type. Like I wrote you don't write the data types of the parameters you pass into a method because they are determined automatically. So your Math.pow(..)
call has to look like power = Math.pow(m, n);
Your code is lacking two }
at the end (for the main method and for the class)
Try to use self-describing names for your variables. A counter named i
may be ok but you could easily rename m
to base
and n
to exponent
and your program would automatically be easier to read.
Upvotes: 1
Reputation: 393846
You don't specify the types of the arguments when you call a method.
Change
power = Math.pow(double m, double n);
to
power = Math.pow(m, n);
You should, however, give an initial value to m
, or the code won't pass compilation.
Upvotes: 3