Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Others/Pow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.io.*;
import java.util.Scanner;

public class Pow{

public static void main( String[] args ){
Scanner s = new Scanner( System.in );
System.out.println( "Enter the integer to calculate power" );
int x = s.nextInt();
System.out.println( "Enter the integer of the power" );
int n = s.nextInt();

if( x == 1 || n == 1 ){
System.out.format( "The result is %d%n", x);
}
else if( n == 0 ){
System.out.format( "The result is 1%n" );
}
else{
int result = 1;
for( int i = 0; i < n; i++ ){
result *= x;
}
System.out.format( "The result is %d%n", result );
}
}
}