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 );

 }
}

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 );
  
 }
}

You forgot to mention the exact problem.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.