Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Power
- {
- public static void main (String[] args ){
- int N;
- int count = 1;
- double X;
- double sum = 0;
- Scanner scan = new Scanner(System.in);
- System.out.println("Enter X");
- X = scan.nextDouble();
- System.out.println("Enter N");
- N = scan.nextInt();
- if(N>=0)
- while(count<=N){
- sum = sum + (X * X); // broken here
- count = count + 1;
- }
- else
- System.out.println("N must be a positive integer.");
- System.out.println(X + " raised to the power " + N + " is: " + sum );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement