Find out if an integer is a power of two - Servlet and JSP

Hy all,
I have to write the following programm using the servlet technology and jsp (with Bean).
"Read a number from the keyboard (through a html file that send the value to the java.class through GET) and find out if this number is a power of two and if it is print on the screen which power it is".
I know how to do the HTML part (the page where I input the value) and I also have an algorythm that checks if an integer is a number of two but I am not very sure how to implement this into a servlet or jsp (with Beans).
Thank you for your help!
Best regards,
Raul
public class PowerOfTwo {  
public static void main(String args[]){  
for(int n=0,limit=16; n<Math.pow(2, limit);n++)
if(isPowerOfTwo(n))
System.out.println(n);
private static boolean isPowerOfTwo(int n) {  
double logNbase2 = Math.log(n)/Math.log(2);
int logNbase2Integer = (int) (Math.floor(logNbase2));
if(logNbase2-logNbase2Integer==0)
return true;
else
return false;
}

Yes, I know it's a messed up code down there. The value that I am trying to check if it is a power of two is sent via the variable "m" to the java class.
Can anyone correct this piece of code please?
Thank you in advance,
Raul
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Putere2 extends HttpServlet{
     public long putere(long m)
     int other = 1;
     if(((~m) & 1) == 1)
     System.out.println("The number is a power of two");
     else
     System.out.println("The number is a NOT A power of two");
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException{
String sm=req.getParameter("m");
String tip=req.getParameter("tip");
long m=Long.parseLong(sm);
long x=putere(m);
PrintWriter out=res.getWriter();
if(tip.equals("text/html")){
String title="Putere";
res.setContentType("text/html");
out.println("<HTML><HEAD><TITLE>");
out.println(title);
out.println("</TITLE></HEAD><BODY>");
out.println("<H1>"+title+"</H1>");
out.println("<P>Puterea este: "+x);
out.println("</BODY></HTML>");
else{
res.setContentType("text/plain");
out.println(x);
out.close();
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException{
doGet(req,res);
     }

Similar Messages

  • I can't remember my security questions and have used the maximum number of tries, how do I find out what my answers are so I can log in and buy some music?

    I can't remember my security questions and have used the maximum number of tries, how do I find out what my answers are so I can log in and buy some music?

    From a Kappy  post
    The Best Alternatives for Security Questions and Rescue Mail
    1.  Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
    2.  Call Apple Support in your country: Customer Service: Contact Apple support.
    3.  Rescue email address and how to reset Apple ID security questions.
    An alternative to using the security questions is to use 2-step verification:
    Two-step verification FAQ Get answers to frequently asked questions about two-step verification for Apple ID.

  • I'm trying to find out why my phone isn't here yet, 30+days, and I can't find a single contact number on this website. Why do I have to sign up with this stupid forum? I have better things to do, like find a new carrier!!

    I'm trying to find out why my phone isn't here yet, 30+days, and I can't find a single contact number on this website. Why do I have to sign up with this stupid forum? I have better things to do, like find a new carrier!!

    800-922-0204 option 4, say agent, ask.

  • HT4910 I try to restore my iPhone last week but I find out that I had lost/missing a lots of photos and messages that I perviously took and send. can iCloud help mr on this?

    I try to restore my iPhone last week but I find out that I had lost/missing a lots of photos and messages that I perviously took and send. can iCloud help mr on this?

    me too

  • How do I find out what I have recently purchased for the app store and iTunes I.e films, songs, albums

    How do I find out what I have recently purchased from the app store and iTunes I.e films, songs, albums &amp; apps?>.<

    On your iPad, you can open iTunes and click on Purchases.  Plus, when you purchase something from iTunes, you should get an email with the purchase details to the email you set up as your Apple ID.  They sometimes take a day or two and with the volume of things being purchased with the millions of new iPads out there in the last 3 days, that may be a bit longer.  I keep every receipt I get for future reference.

  • I cannot seem to find out if I have one or two accounts by mistake?with the Guardian, my  subscription seems to have doubled. I stopped it now I cant find out  which one I had. I wanted the Guardiain and the Observer combined but on  the ipad and mac.

    Looking at my apple or itunes account it read two different dates for collecting my Guardian and Observer subscription. Being wowrrried I was paying for it twice I cancelled it. Now  how do i find out if I was over impetius or should just start again?Also can one get this double subscription to be on both the Mac and on the ipad?

    Looking at my apple or itunes account it read two different dates for collecting my Guardian and Observer subscription. Being wowrrried I was paying for it twice I cancelled it. Now  how do i find out if I was over impetius or should just start again?Also can one get this double subscription to be on both the Mac and on the ipad?

  • How can I find out the angle of a straight line between two anchor points?

    I would like to extend a line which is at a given angle (not 45,90 degree). Is there a quick and reliable way to do this? or to find out the angle of a segment?
    What I'm doing at the moment is just direct selecting an anchor point and using the visual guides to extend it. I don't think this is exact though so was I wondering if anyone had any techniques for doing this?
    Thanks!

    portfelio,
    Smart Guides are your friends.
    As a general solution, you may:
    1) With the Line Segment Tool ClickDrag between the two Anchor Points (Smart Guides say anchor);
    2) With the appropriate Reference Point selected in the Transform palette, increase the W or H value and Ctrl/Cmd+Enter;
    3) Lock the new auxiliary line;
    4) ClickDrag the relevant Anchor Point of the original line along the extended auxiliary line (Smart Guides say path);
    5) Unlock and delete the auxiliary line.
    After 1), you may also click the Line Segment Tool to see the angle.
    Or,  in a case with a straight path (segment), you may use the Scale Tool:
    1) (Direct) Select the straight path (segment);
    2) Switch to the Scale Tool and Click the Anchor Point that is to stay, then ClickDrag the one to move (Smart Guides say uniform when you are dragging in the right direction).

  • I sent my ipod nanooff and i have not recieved it back how do i find out where it is?, I sent my ipod nanooff and i have not recieved it back how do i find out where it is?

    I sent my iPod nano 1st generation off for the iPod nano recall ststem. However I have not yet recieved my new iPod nano or an e-mial to confirm arrival or to help me understand where it is. How do i find out where it is? Or if it is ever liable for the recall process?

    Solution may be found if you search in the "More Like This" section over in the right column.

  • The other day at school i had lost/stolen ipod touch i had signed up with apple but i havent download the app (find my iphone) is there any way i can find out when my ipod touch gets connected to a wifi and track it

    how do u track an ipod touch when its connected to a wifi and how do u find out when its your stolen ipod touch is connected

    If you set up the Find My iPod service prior to the iPod going missing - the app is for tracking an iOS device from another iOS device - then there is a chance that can be tracked, though it depends on a number of factors (the iPod is turned on, connected to a WiFi network, and has not had the Find My iPod service disabled). Log into icloud.com and go to the Find My iPhone section. Note, though, that you'll only get the location of the WiFi router to which the iPod is connected; there's no way to pinpoint the exact location of the iPod itself.
    If you did not set up Find My iPod, then there is no way to track it. Notify the police and change any passwords for any online accounts you may have used from your iPod (the iTunes Store, for instance). 
    Regards.

  • I have recently installed Mavericks and since then I have been unable to shut down or log out of my mac.  I work with two screens and now I seem to have programmes at the top of both screens which I didn't before.  any advice?

    I have recently installed Mavericks on my desk top and since then I have been unable to switch off my computer without crashing it. I work with two screen and now I seem to have the menu bar on the second screen as well which I did not have before.  Can you please help me?

    Dr Bettina, I had similar problems with Mavericks. I installed it on a Mini and a 13" MacBook Pro. I can't speak to your disdplay issues, but I can confirm the inability to logout, shut down, or restarft without a forced, power button shut down. I can also report frequent System Prefs freezes and finder issues, like folder contents taking half a minuite or more to render, or not appearing at all. And while a few Adobe CC apps actually ran faster, InDesign ran like molasses uphill in Decemner.
    I tried uninstalling or disabling numerous 3rd party apps and pref panes. I unplugged everything but the keyboard, ran DiskWarrier, repaired permissions, did fsck -f, trashed various preference files, reinstalled the OS... You name it, and I tried it — short of a potion using eye of newt.
    After two days of totally hosed productivity, I restored OS 10.8.5 on the Mini so I could actually get some work done. However, I've decided to leave Mavericks on the MBP as a sort of crash dummy, and will install and thoroughly test all updates until stability has been achieved. Then — and only then — will I upgrade the Mini to Mavericks, even if it means waiting 'til a .2 or even .3 update.
    Good luck to you...

  • My six year old set up the restrictions code on my iPad and he doesn't remember the code he used. How can I find out the code. I already tried reseting the iPad and it did not work.

    How can I retrive the passcode for Restrictions? I already tried reseting my iPad to factory settings but did not work.

    I believe there is a way to reset the settings only, but I'm not sure if that applies to restrictions. Maybe there is a way on the computer?

  • ICal icon on my Mac Book Air displays a circled number at the upper right corner as does Mail for new emails - how do I find out what item(s) that number is referring to? And why does it show up on the Mac Book Air and not my 4S iPhone?

    A circled number appears in the upper right corner of the iCal icon on my Mac Book Air. What does it mean? How do I resolve it? Why doesn't it appear on my 4S iPhone via the iCloud?

    Glenn,
    That number means that you have an event invitation. Use iCal>View>Show Notifications to choose what to do with the notification. Since OS X 10.7.2 is required for iCloud integration, I am not surprised that there are anomalies between the iPhone and the MacBook Pro.

  • How to find out if Silverlight is disabled in Mozilla's add-ons and fix it so I can insert attachments into my email.

    I cannot insert attachments, photos, etc. into my emails in Firefox 4. Windows Live Hotmail solutions had me reinstall Silverlight. It didn't work. They now suggest contacting you to see if Silverlight is being disabled in the add-ons sections of my browser. I can attach files in Explorer but not in Firefox. How do I check to see if Silverlight is being disabled and fix this problem?

    Click the Firefox button, go to Add-ons | Plugins. It appears to be enabled already though because your system details show "4.0.60310.0" which is the latest version of Silverlight.

  • How do I find out who is attached to my sharing of my account and remove and add someone? Is 5 devices the limit?

    Devices sharing is 5?
    Where do I go to remove and add a devic

    Hey 1980justme!
    I have an article for you that can help you address this question:
    iTunes Store: Authorize or deauthorize your Mac or PC
    http://support.apple.com/kb/ht1420
    Thanks for coming to the Apple Support Communities!
    Regards,
    Braden

  • How to find out if LOB is stored "IN ROW"?

    Hi,
    If I have a compressed secuerfile LOB defined as "enable storage in row", is there any way to find out how many LOBs are stored in the table segment and how many where moved "out" in the lobsegment due to exceeding the approx. 4000 byte limit?
    If I haven't defined the question clearly enough, please let me know.
    Thanks in advance for any answer and regards,
    Jure

    Maybe I didn't explain the question well. I didn't ask how to find out from the data dictionary whether the LOB is defined as "enable storage in row" or "disable storage in row". I asked how to find out how many LOBs (LOB instances) are stored "in row" (in the table segment) and how many in the lobsegment, given that the LOB is defined as "ENABLE STORAGE IN ROW" with enabled compression.
    If I write the question in another way:
    Suppose I have a heap table with a LOB column defined as SECUREFILE COMPRESS HIGH, e.g.:
    CREATE TABLE test1 (id INTEGER, test_b BLOB)
    TABLESPACE USERS
    LOB (test_b) STORE AS SECUREFILE (
      TABLESPACE USERS
      COMPRESS HIGH  
      ENABLE STORAGE IN ROW
      CHUNK 8192
    )There are 1000 rows of data in the TEST1 table. The data length in the test_b BLOB varies from 100 bytes to 1MB, so some of those BLOBs are stored in the table segment (those with size approx. smaller than 4000bytes as described here http://download.oracle.com/docs/cd/E11882_01/appdev.112/e18294/adlob_tables.htm#sthref320) and some are stored in the lobsegment. My question is, how to find how many LOBs are stored in the table segment and how many are stored in the lobsegment due to exceeding approximately 4000 bytes (4000 bytes being the limit where the LOB is moved out of the table segment).
    The obvious answer could be to check the size of the LOB and if it is less than 4000 bytes (actually less than the size reported by the DBMS_LOB.GETCHUNKSIZE function) and based on that know where the LOB data is stored, but there are two problems with that approach:
    - how to account for data compression
    - even if the lob is defined as "ENABLE STORAGE IN ROW" and it's less than 4000 bytes in size, it could still be stored out of the table segment: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e18294/adlob_tables.htm#ADLOB45273 : "If you update a LOB that is stored out-of-line and the resulting LOB is less than approximately 4000 bytes, it is still stored out-of-line."
    I hope I asked clearly this time.
    Regards,
    Jure

Maybe you are looking for

  • Error installing 10GR2 on RHEL4 while root.sh

    This is a listing of terminal [root@newmulti /]# /app/oracle/oracle/product/10.2.0/db_2/root.sh Running Oracle10 root.sh script... The following environment variables are set as: ORACLE_OWNER= oracle ORACLE_HOME= /app/oracle/oracle/product/10.2.0/db_

  • HP Officejet 6500 e709n - Solution Center Scan Malfunctio​n

    I've recently purchased a new laptop with Windows 8.1 already installed on it.  I've had my HP 6500 for years and it has worked perfectly - all functions.  When going online to download the drivers to my new laptop, all messages indicate the installa

  • Printer won't print email with black ink, how do I correct this?

    I am new here, and seek some help. My wife's i-Mac computer has a problem of not printing email with black ink. However, the printer will print email text in all colors, but not with black ink. The printer goes through all the motion/movements like i

  • Bible software

    Having just entered the realm of the MAcBook and lovin' it, I now need to find an application that will help me do research and exegetical work in the Bible. I used BibleWorks 6 when I lived in the dark side, and need a program of similar capacity wi

  • Relationship Of cost Center & Profit Center

    Hello Can anybody explain what could be cons of having relations of 1:N between profit center & Cost center Regards