In Java, how do I write a loop that takes a number as input and computes 2 to the power of that number?
437411
ok.. here ya go:\n\n1) first, for accepting a number from the user , u have to use the input Stream .\n\nfor example :\n\nBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\nbr is the object to the BufferedReader class , which is responsible for accepting values from the console.\n\n2 ) now, to accept a value ...i.e to put it in a variable, give a print statement (optional) : something like System.out.println("enter value");\n\nand use the line : \nvarname = br.readLine(); \nto accept the user's data into the variable varname.\n\n3 )now, since ur number's max value is 30, put an if condition , if(varname<=30).\n\nand in that if block, put a for loop : \n\nfor(int i=1;i<=varname;i++)\n\nand in the for loop, put the statement : var2 *=2;\n\nwhere var2 is another variable of the integer type, declared at the start of the main() block.\n\nprint out the value. System.out.println(var2) ;\n\nhope i 've answered ur qn.\n\n: )
428865
order of operation - parenthesis, power, multi/divide, and add/subtract
551157
Alright. Here's the deal. \n\nSince this is your first course, here are some tricks.\n\nIf the program will have an input of name, month,and day the hurricane, then you will need 4 variables. A string and 3 integers.\n\nHow will you use them? How many times will you repeat the loop?\n\nIf you do not know how many times you want it to be repeated, then  the wisest choice is a do/while. Otherwise, let the user tell you how many times it should be done.\n\nYou will make those 4 variables. They should be arrays, make sure they are big enough.\n\nit will be something as simple as this:\n\nlet the user tell you how many times he want it to be repeated:\n\nint timesToBeRepeated = 0;\ncin >> timesToBeRepeated;\n\nfor ( int i = 0; i < timesToBeRepeated; i++ )\n{\n\n      cout <<"Enter the Hurricane name: &#92;n";\n      cin >> hurricaneName[i];\n         .\n         .\n         .\n}\n\nthen, to print it out,  just do something like this:\n\ncout <<"Hurricane Name"<<"      <<"Day"<<..<<endl;\n\nthen:\n\nfor ( i = 0; i < timesToBeRepeated; i++ )\n  cout << hurricaneName[i] <<"   "<<....<<endl;\n\nWork out the rest, but that is pretty much it., Any doubt, contact me.
751233
I'm not sure why you are avoiding the loop, but you could use recursion instead. If I understand your question correctly this function in c++ should give you your desired results.\n\nint sum(int nbr){\n    if(nbr > 0){\n           return(nbr%10 + sum(nbr/10));       \n    }\n    else{\n         return(0);\n    }\n}\n\nIf you called it with a number such as 256, it would return an answer of 13, or the sum of each digit in the integer.
767431
you need to cast the value. try this\n\nDouble.parseDouble(someStingValue);\nyou can use the variable as a double then.
1146301
There is a book called "the Trachtenberg System" which explains a lot of computational shortcuts you can do in your head. It's probably in your local library.\nHere's an example of how to square a 2-digit number\n Rules: \n1. Square the second digit \n2. Multiply the two digits and double \n3. Square the first digit \nExample:\n34^2 (^2 is used for the "squared" symbol)\n   6          4^2  is 16; write 6, carry 1 \n  5          3x4x2 is 24, +1(carry) is 25; write 5, carry 2 \n11            3^2  is 9, +2(carry) is 11\n1156 \n34^2  = 1156
134673
I'd set it up like this...\n36      80\n--   =  --\n n      100\n\ncross multiply and solve for n
759262
The rules for simplifying integer exponents are pretty simple:\n\nhttp://en.wikipedia.org/wiki/Exponentiation
1082973
I answered in your other post but I'll re-post the answer here:\n\nYou elevate the number to the power 2 like this:\n\nx^2\n\nYou should still do the normal product but it is easier to thing you et the square of a certain number and most calculators already have the elevate to the second power function integrated\n\nCynthia
816710
Create an outer for loop that will loop from 7 down to 0, with a step of 2.\n\nCreate one inner loops.\n\nThe inner loop should take the value of i, place it in another variable and count down to 0.\nThen print out the dollar signs for each iteration of this loop.
702009
First try to figure out what is the largest power of two in the given number. in your example, it's 128 which is equal to 2^7.\nThe exponent of 2 signifies that we have a 7 bits or 7 combination of 1 and 0.\nnext, is subtract 128 from the given #.\nthat is,\n141 - 128 = 13.\nNow using the result, find the next largest power of 2. This is\n8 which is equal to 2^3.\nnext, subtract again from the result\n13-8=5.\nthen we have 4 which is 2^2.\nsubtract again.\n5-4=1\nthus the next power of 2 is 1 which is 2^0.\n\nAll the exponents signifies the the position of bit that is a high or equal to 1.\n\nIn your example 144 in binary is equal to\n\n76543210>>>>pertains to the exponent of 2\n10001101>>>>binary equivalent\n\n\nThus\n144 (decimal) = 10001101 (decimal)\n\nIsn't that simple.\n\nYou will figure it out from the start how large or how many bit will a given # of yours contain and you you will identify your MSB.\n\nInstead of dividing by two which will give you the LSB.
131932
it cant but .99 repeating is equal 2 one!!!! o unless u do a number 2 the 0th power \nex. (5^0)+(2+2)
138197
Using what tool?\n\nInternet access?  Use Google Calculator -- see http://www.google.com/features.html#calculator\n\nPencil and paper?  Try iterations of Newton's method.\n\nCalculator?  Get a rough estimate by hitting the sqrt key ten times, subtract one, divide by ten, add one, then hit the "x squared" key ten times.\n\nLog tables?  Look up the logarithm, divide by ten, find antilogarithm.\n\nCalculator with x^y button?  Raise to the 0.1 power.\n\nCalculator with e^x and ln buttons?  Take ln, divide by ten, take e^x.\n\nC compiler?  Include <math.h> and use the pow function.\n\nJava?  Use Math.pow.\n\nFORTRAN or Perl?  Use x ** 0.1.
885437
The last two digits are '25'. \n\n(This is the same for ANY integer power of 5 greater than 1).\n\nThe calculator won't give you the answer since it is not accurate enough.
339889
You will get a error because you need a loop condition it cant be just 1. for example to print god 5 times make loop condition like for(i=0; i <=5;i++) then it will print "god" five times.
894472
Use a calculator.  Enter [2] [log] for the first one.
188148
try this:\n\nnumber of elements in the array is "n"\nnumbers are stored in array "Numbers"\n\nfor (i = 0; i < n - 2; i++)\n{\n   for (j = i + 1; j < n - 1; j++)\n   {\n      for (k = j + 1; k < n; k++)\n      {\n         cout << Array[i] << "," << Array[j] << "," << Array[k];\n      }\n   }\n}