Write a program that takes a 5 digit number and calculates
2 power
that number and prints it.

Answer Posted / r.dhanunjay

import java .io.*;

public class Digits {

public static void main(String[] args) throws IOException
{


try
{
System.out.println("Enter the number with 5 didgits");
BufferedReader br= new BufferedReader(new
InputStreamReader( System.in));

String str = br.readLine();
int i =Integer.parseInt(str);
int j =String.valueOf(i).length();
if(j==5)
{
double k =Math.pow(i,2);
System.out.println(k);
}
else
{
System.out.println("enter only 5 didgits number");
}
}
catch(IOException e)
{
System.err.println();
}
}



}

Is This Answer Correct ?    7 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why are getters and setters used?

766


What is indexof in java?

730


How do listeners work?

734


What is the size of integer?

815


What are "methods" and "fields"?

765


What is mean by encoding?

811


Can a constructor have different name than a class name in java?

814


Difference between notify() method and notifyall() method in java?

744


Can java hashmap have duplicate keys?

699


Which keyword specify that a variable is effectively final ?

755


Give a practical example of singleton class usage?

773


Can we call virtual funciton in a constructor ?

1940


Does java allow default arguments?

769


What is a two-pass assembler?

791


What is finalize()?

867