Raised To Power

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Raised To Power as PDF for free.

More details

  • Words: 278
  • Pages: 2
RaisedToPower /* * Filename: "RaisedToPower.java" * Created by 1,000_naymes; for ICT 352 * Purpose: to gather values for x and n and then calculate the value of x raised to n */ import javax.swing.JOptionPane; public class RaisedToPower { public static void main( String[] args ) { /************************************************************** declare and initialize variables **************************************************************/ String openingMessage, xInputMessage, xString, xMessage, nInputMessage, nString, nMessage, resultMessage, resultInputMessage, resultString, choiceString, showResultMessage; double x, result; int n, choice; /************************************************************** display opening message **************************************************************/ openingMessage = "Welcome to 1KN's RaisedToPower program, which will ask you for two numbers, \n and then raise your first number to the second."; JOptionPane.showMessageDialog( null, openingMessage ); /************************************************************** input for first number (x) - a decimal number **************************************************************/ xInputMessage = "Please enter a value for x (a decimal number)."; xString = JOptionPane.showInputDialog( xInputMessage ); x = Double.parseDouble( xString ); //converting string to double /************************************************************** input for second number (n) - an integer between 1 and 10 **************************************************************/ nInputMessage = "Please enter a value for n (a whole number between 1 and 10)."; nString = JOptionPane.showInputDialog( nInputMessage ); n = Integer.parseInt( nString ); //converting string to double /************************************************************** calculating result Use a switch statement to calculate x raised to the n power (x^n). (Hint: Use Math.pow(x, n).) **************************************************************/ Page 1

RaisedToPower result = Math.pow( n, x ); resultInputMessage = "You entered: \n" + x + " raised to the " + n + ". \n \n Please enter 1 to view your result."; choiceString = JOptionPane.showInputDialog( resultInputMessage ); choice = Integer.parseInt( choiceString ); showResultMessage = "Your result is:

" + result;

switch( choice ) { case 1: JOptionPane.showMessageDialog( null, showResultMessage ); break; } System.exit(0); } //end main } //end class

Page 2

Related Documents

Raised To Power
November 2019 8
Heckles Raised But It's True
November 2019 36
Apax Funds Raised Worldwide
October 2019 13
Priobio To Power Arriva
December 2019 9
Power-dc-to-dc.pdf
October 2019 22