Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Power
  4. {
  5.   public static void main (String[] args ){
  6.     int N;
  7.     int count = 1;
  8.     double X;
  9.     double sum = 0;
  10.     Scanner scan = new Scanner(System.in);
  11.    
  12.     System.out.println("Enter X");
  13.     X = scan.nextDouble();
  14.     System.out.println("Enter N");
  15.     N = scan.nextInt();
  16.    
  17.     if(N>=0)
  18.         while(count<=N){
  19.             sum = sum + (X * X);  // broken here
  20.             count = count + 1;
  21.         }
  22.        
  23.     else
  24.         System.out.println("N must be a positive integer.");
  25.    
  26.     System.out.println(X + " raised to the power " + N + " is: " + sum );
  27.      
  28.   }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement