Hey guys! This is a relativity simple program. It compiles fine but when I try to execute there is a problem. Any insight or advise would be greatly appreciated. Thank you

import java.util.Scanner;
public class Power
{

 public static void main( String[] args )
 {

 Scanner input = new Scanner( System.in );

  System.out.print( "Enter two numbers separated by spaces: ");
  double x = input.nextDouble(); //read first number
  double y = input.nextDouble(); //read second number

  double z = x * x;

  for( int i = 1; i <= y; i++)
  {
   z *= x;

  }

  System.out.printf( "the answer is %d ", z );

 }
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

Sorry... posted the code wrong...

import java.util.Scanner;
public class Power
{
 
 public static void main( String[] args )
 {
  
 Scanner input = new Scanner( System.in );
   
  System.out.print( "Enter two numbers separated by spaces: ");
  double x = input.nextDouble(); //read first number
  double y = input.nextDouble(); //read second number
  
  double z = x * x;
  
  for( int i = 1; i <= y; i++)
  {
   z *= x;
    
  }
  
  System.out.printf( "the answer is %d ", z );
  
 }
}

change below line
----------------------------------------------
System.out.printf( "the answer is %d ", z );
-----------------------------------------------
to

-------------------------------------------
System.out.printf( "the answer is %f ", z );
--------------------------------------------

This question has already been answered. Start a new discussion instead.