1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
madreJ [45]
2 years ago
13

Write a java program to input a number from the user and tell if that number is a power of 2 or not.

Computers and Technology
1 answer:
Sophie [7]2 years ago
4 0

Answer:

 public static boolean isPowerOfTwo(int n) {

   long exp = Math.round(Math.log(n) / Math.log(2));

   return Math.pow(2, exp) == n;

 }

Explanation:

The opposite of power-of-2 is the 2-log, which is calculated using any log divided by log(2).

I'm sure you can do the input part yourself!

You might be interested in
Moving through a neighborhood trying to locate open wireless access points is called ________.
disa [49]
<span>Moving through a neighborhood trying to locate open wireless access points is called wardriving. 
</span> The action wardriving is performed by a person in a moving vehicle (car, bike..) who is using a laptop or smartphone and wants to catch a Wireless LAN (WiFi) network. For this purpose there is software <span>freely available on the Internet.</span>
7 0
3 years ago
To close the ____ view, click File on the Ribbon or click the preview of the document in the Info gallery to return to the docum
nordsb [41]
Your answer would be D,
7 0
4 years ago
Can someone tell me what Identity Theft in there own words
gavmur [86]
Stealing someone else’s identity or identification
8 0
3 years ago
A ball is released from a 10 m high roof and bounces two thirds as high on each successive bounce. After traveling a total of 40
skelet666 [1.2K]

Answer:

Four times traveling 40,12345 mts

Explanation:

We can express this as a sum as follows

\sum_{i=1}^4(10\cdot  \frac{2}{3}^{i - 1} + 10\cdot  \frac{2}{3}^{i } ) = 3250/81=40.12345679

The first term is the dropping part and the second is the upward motion. this sums up to 40,12345 m after bouncing four times. As a program we could write using the while loop.

distance=0;

i:=0;

while distance<40 do

i:=i+1;

distance:=distance+ 10\cdot  \frac{2}{3}^{i - 1} + 10\cdot  \frac{2}{3}^{i };

end while;

Here the answer is in i and the closest distance traveled after reaching 40 is in the variable distance.

4 0
4 years ago
pls Which of the following statements is false? a. Having a first aid kit in an office is necessary b. Accidents happen, so it i
Dovator [93]
I thinks it’s B if not I’m sorry:)
7 0
3 years ago
Read 2 more answers
Other questions:
  • The flowchart shape for input or output is an oval. <br> a. True <br> b. False
    6·1 answer
  • Select the correct answer from each drop-down menu.
    10·1 answer
  • The Task Manager cannot be used to turn Services on and off.<br> True or False?
    8·2 answers
  • Which of the following is not one of the most common causes of electrical accidents ?
    8·2 answers
  • Network Industries, Inc., wants to monitor its employees’ electronic com-munications. To avoid liability under laws related to e
    12·1 answer
  • Which step of the laser printer imaging process requires troubleshooting if a printer produces ghost images on output pages?
    13·1 answer
  • As discussed in the video, parallax measurements allow us to calculate distances to stars for which parallax is detectable. Supp
    14·1 answer
  • Microsoft ____________________ is a complex, full-featured firewall that includes stateful packet filtering as well as proxy ser
    10·1 answer
  • Select the correct answer.
    8·1 answer
  • 1. What is a digital networking app?
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!