help me , im confused!!!!

import java.util.Scanner;

public class Eiks

{

public static void main (String args [])

{

Scanner scan = new Scanner (System.in);

int base, exponent;

int ans;

System.out.println("Enter your base:");

base = scan.nextInt();

System.out.print("Enter your exponent:");

exponent = scan.nextInt();

prod = base ^ exponent;

System.out.print("the prod is : " + prod);

}

}

* for example base = 2 , exponent = 3 the ans is 8 (2*2*2)

my program is running but the operation is wrong , the prog giving me a wrong ans. .

please help. .

Re: help me , im confused!!!!

Okay, here is the problem, the '^' operator in java is NOT how you do an exponent. It is actually XOR, a binary math function. Instead of "prod = base ^ exponent;", use "prod = Math.pow(base, exponent);"

Hope that helps!

Re: help me , im confused!!!!

Quote:

Originally Posted by

**wrightm96**
Hope that helps!

thanks it really helps . :D iLy lol