Java Quiz: Show your java strength

14 views
Skip to first unread message

Kamlesh Paunikar

unread,
Sep 21, 2009, 11:44:41 AM9/21/09
to Code Gurukul
Hello

Can u write a program to find 2 power n? where n is input.
If you think "This is very simple program" then please write the
complete program in Java as your post.

Thanks
KP Solutions
http://www.kpsolutionsindia.com/KPSolutionsIndia

Rahul Raja

unread,
Sep 22, 2009, 11:44:56 AM9/22/09
to Code Gurukul


On Sep 21, 8:44 pm, Kamlesh Paunikar <kamleshpauni...@gmail.com>
wrote:
Program:

class example
{
public static void main(String arg[])
{
if(arg.length>1)
{
System.out.println("Invalid no. of arguments");
}
else
{
String s=arg[0];
int n=Integer.parseInt(s);
double value=Math.pow(2,n);
System.out.println("Value="+value);
}
}
}

Thanks,
Rahul Raja

Karan Amarnani

unread,
Sep 22, 2009, 5:52:43 AM9/22/09
to code-g...@googlegroups.com
Hello Sir,

I have tried to write the program,please find the attached file.
Looking forward for your suggestions.

With Regards,
KaranAmarnani

PowerGenerator.java
XPowerYGenerator.java

Sumit Desai

unread,
Sep 24, 2009, 12:10:48 AM9/24/09
to Code Gurukul


On Sep 21, 8:44 pm, Kamlesh Paunikar <kamleshpauni...@gmail.com>
wrote:
Hello sir,
i have made this program....
pls check it.

Program:-

class Power
{

public long findPower(int n)
{
int c=1;
long pow=1;
for(int i=0;i<n;i++)
{
pow=pow*2;
}
return pow;
}
}


class MyPower
{
public static void main(String arg[])
{
Power p1=new Power();
long p=p1.findPower(4);
System.out.println("Value= "+p);
}
}
Reply all
Reply to author
Forward
0 new messages