Skip to content

Commit e5ce68f

Browse files
committed
1 parent a0fd638 commit e5ce68f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Others/Pow.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.io.*;
2+
import java.util.Scanner;
3+
4+
public class Pow{
5+
6+
public static void main( String[] args ){
7+
Scanner s = new Scanner( System.in );
8+
System.out.println( "Enter the integer to calculate power" );
9+
int x = s.nextInt();
10+
System.out.println( "Enter the integer of the power" );
11+
int n = s.nextInt();
12+
13+
if( x == 1 || n == 1 ){
14+
System.out.format( "The result is %d%n", x);
15+
}
16+
else if( n == 0 ){
17+
System.out.format( "The result is 1%n" );
18+
}
19+
else{
20+
int result = 1;
21+
for( int i = 0; i < n; i++ ){
22+
result *= x;
23+
}
24+
System.out.format( "The result is %d%n", result );
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)