Question

Evaluate Exponent: Declare a double variable called result and initialize it to 1.0; Ask the user for two values - one for th
0 0
Add a comment Improve this question Transcribed image text
Answer #1
Exponent.java

public class Exponent {
    public static void main(String[] args) {
        // scanner for taking input
        Scanner scanner = new Scanner(System.in);
        // initialzed result to 1.0
        double result = 1.0;
        System.out.println("Enter a base and an exponent to evaluate:");
        float base = scanner.nextFloat();
        int exponent = scanner.nextInt();
        // checking if exponent has invalid value
        if(exponent == 0){
            System.err.println("Invalid value of exponent : "+exponent);
        }
        else {
            // using do while finding result
            int loop = 0;
            do{
                result *=base;
                loop++;
            }while (loop<exponent);
            // printing the result
            System.out.println(base+" to the "+exponent+" is "+result);
        }

    }
}

//OUT

Enter a base and an exponent to evaluate: 2 16 2.0 to the 16 is 65536.0

Please do let me know if u have any concern..

Add a comment
Know the answer?
Add Answer to:
Evaluate Exponent: Declare a double variable called result and initialize it to 1.0; Ask the user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a class called Play that has an InputReader as an instance variable. Be sure to...

    Create a class called Play that has an InputReader as an instance variable. Be sure to initialize it in the constructor. The class has two methods. Write a method with this signature: Write a method with this signature: public void stringPlay() The method prompts the user for a string, reads it in, and then displays the string as many times as the length of that string. The output string should be formatted with the first letter uppercase and the rest...

  • Please code this in java: The purpose of this assignment is to: Read double data in...

    Please code this in java: The purpose of this assignment is to: Read double data in to a TreeSet where each datum inserted is Math.abs(datum) (i.e., no negative values are inserted). NOTE: This will (i) sort the data placed into the TreeSet, and, (ii) remove duplicate values since no duplicates are allowed (i.e., duplicates will not be inserted). Create a list iterator. Iterate backwards through the TreeSet (i.e., from the largest value to the smallest) outputting all elements * -1.0....

  • I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according...

    I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the...

  • create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines....

    create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the...

  • IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. •...

    IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. • Declare a global enum variable that will support 10 values – each representing an ant colony {A, B, C, D, E, F, G, H, I, J}. • In the main function, o Declare a 2-dimensional array of size the global integer constant, SIZE. The number of rows and columns should be equal to SIZE, which would make this a square matrix. This array will...

  • /*********************************** * * Filename: poly.c * * ************************************/ #include "poly.h" /* Initialize all coefficients and exponents...

    /*********************************** * * Filename: poly.c * * ************************************/ #include "poly.h" /* Initialize all coefficients and exponents of the polynomial to zero. */ void init_polynom( int coeff[ ], int exp[ ] ) { /* ADD YOUR CODE HERE */ } /* end init_polynom */ /* Get inputs from user using scanf() and store them in the polynomial. */ void get_polynom( int coeff[ ], int exp[ ] ) { /* ADD YOUR CODE HERE */ } /* end get_polynom */ /* Convert...

  • Lab Objectives Be able to write methods Be able to call methods Be able to declare...

    Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...

  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • I need help with this assignment. It's due Tuesday at 8 AM. Please follow the instructions thorou...

    I need help with this assignment. It's due Tuesday at 8 AM. Please follow the instructions thoroughly as to not use any advanced material we may not have gone over in class. The instructions let you know what all should be used. Thanks! Use only what you have learned in Chapters 1 - 7. Use of "advanced" material, material not in the text, or project does not follow the instructions, will result in a GRADE OF 0% for the project....

  • Your task is to develop a large hexadecimal integer calculator that works with hexadecimal integers of...

    Your task is to develop a large hexadecimal integer calculator that works with hexadecimal integers of up to 100 digits (plus a sign). The calculator has a simple user interface, and 10 \variables" (n0, n1, ..., n9) into which hexadecimal integers can be stored. For example a session with your calculator might look like: mac: ./assmt1 > n0=0x2147483647 > n0+0x3 > n0? 0x214748364A > n1=0x1000000000000000000 > n1+n0 > n1? 0x100000000214748364A > n0? 0x214748364A > exit mac: Note: \mac: " is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT