package Loops;
import java.util.Scanner;
public class power {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
System.out.println("the a is "+a);
int b=sc.nextInt();
System.out.println("the b is "+b);
int result=1;
for(int i=0;i<b;i++) {
result=result*a;
}
System.out.println("the a raise to b is "+result);
}
}
output:-
2
the a is 2
3
the b is 3
the a raise to b is 8
import java.util.Scanner;
public class power {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
System.out.println("the a is "+a);
int b=sc.nextInt();
System.out.println("the b is "+b);
int result=1;
for(int i=0;i<b;i++) {
result=result*a;
}
System.out.println("the a raise to b is "+result);
}
}
output:-
2
the a is 2
3
the b is 3
the a raise to b is 8
Comments
Post a Comment