Monday 23 March 2020

DISPLAYING POWER USING JAVA LANGUAGE

Q-21-Write a java program that displays the following table. Cast floating-point numbers into integers.

a  b  pow(a, b)                           
1  2       1                                                                                                           
 2  3       8                                                                                                                                             
3  4       81                                                                                                                                           
 4  5      1024                                                                                                                                         
5  6      15625

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a;
int b;
System.out.println("Enter The Value Of a & b :");
a=sc.nextInt();
b=sc.nextInt();
System.out.println("a    b     pow(a,b)");
System.out.println(   a+ "    "+b +"      "+ Math.pow(a, b));
System.out.println(   ++a+ "    "+ ++b +"      " + Math.pow(a, b));
System.out.println(   ++a+ "    "+ ++b +"      " + Math.pow(a, b));
System.out.println(   ++a+ "    "+ ++b +"      " + Math.pow(a, b));
System.out.println(   ++a+ "    "+ ++b +"      " + Math.pow(a, b));
}


}

OUTPUT :
Enter The Value Of a & b :
1
2
a    b     pow(a,b)
1    2      1.0
2    3      8.0
3    4      81.0
4    5      1024.0

5    6      15625.0

No comments:

Post a Comment