This week's book giveaway is in the Android forum. We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line! See this thread for details.

public class ForCycle_04 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("begin");
int num = sc.nextInt();
System.out.println("end");
int power = sc.nextInt();
int result = 1;

for (int i = 0; i < power; i++) {
result = result * num;
}
System.out.println(result);
}
}

public class ForCycle_04 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("begin");
int num = sc.nextInt();
System.out.println("end");
int power = sc.nextInt();
int result = 1;

for (int i = 0; i < power; i++) {
result = result * num;
}
System.out.println(result);
}
}

if N == 64 return 0 , please give me a solution.

Thanks in advance!

The source code that you provided doesn't have an N, so don't know what you mean by "if N == 64 return 0". Second, after clarifying that, please explain what issues you are having with the code that you provided.

Mark Guo wrote:Can you give me a solution to handle all number type?

A long has a larger range than an integer. A java.math.BigInteger has a range that is even larger than that. For 64 to the 64th power, the java.math.BigInteger class should be able to handle it.

You realise you can change that linear complexity algorithm to run in logarithmic complexity?
If the index divides exactly by two, you halve the index, and square the result. Remember to get x squared, you write x * x.