We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a0fd638 commit e5ce68fCopy full SHA for e5ce68f
Others/Pow.java
@@ -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