Computer Applications
Write a program in Java to input two numbers (say, n and m) using the Scanner class. Display the results of n raised to the power m (nm) and mn.
Java
Input in Java
33 Likes
Answer
import java.util.*;
public class KboatExponent
{
public static void main(String args[])
{
int n, m;
double expo;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number (n): ");
n = in.nextInt();
System.out.print("Enter a number (m): ");
m = in.nextInt();
expo = Math.pow(n,m);
System.out.println(n + " raised to the power "
+ m + " = " + expo);
expo = Math.pow(m,n);
System.out.println(m + " raised to the power "
+ n + " = " + expo);
}
}
Output

Answered By
20 Likes
Related Questions
Name a package needed to import scanner class
In what way can the following data be read from the scanner object?
(a) Integer type
(b) Float type
(c) Double type
(d) String type
(e) Boolean type
Write a program in Java to input perpendicular and base of a right angle triangle using the Scanner class. Calculate and display its hypotenuse using the formula given below:
h = √(p2 + b2)A shopkeeper offers 30% discount on purchasing articles whereas the other shopkeeper offers two successive discounts 20% and 10% for purchasing the same articles. Write a program in Java to compute and display the discounts.
Take the price of an article as the input.