## Problem with this line of code

Put your programming skills to the test in these challenges.

### Problem with this line of code

So, today was my first day of Java programming summer school. I did an assignment and decided that it wasn't enough. So, I did more. I love programming but the assignment was too simple. When doing more work, I ran into a difference between these two lines:

Code: Select all
` double c = Math.sqrt(a*a + b*b);`

and
Code: Select all
`double c = Math.sqrt(a^2 + b^2);`

One of them gives me 1.0. The other gives me 6.4. Why? What is the difference between the two lines?

Contributor

Posts: 728
Joined: Wed Nov 19, 2014 1:19 am
Blog: View Blog (0)

### Re: Problem with this line of code

Because '*' is a multiplicative operator and '^' is a bitwise exclusive OR operator.
Social Engineering:
<cen> .lua print ('Tsyn 9.47.-u 3 12 5')
* slickery has quit (User has been banned from HackThisSite (Attempting to use a SpyBot))
* cen has quit (User has been banned from HackThisSite (Attempting to use a SpyBot))

Turn
Poster

Posts: 120
Joined: Tue Feb 17, 2015 5:42 am
Blog: View Blog (0)

### Re: Problem with this line of code

So then, I should try two asterisks? That's the way I used to do it:

Code: Select all
`double c = Math.sqrt(a**2 + b**2);`

But it gives me an illegal start of expression error. Why?
Contributor

Posts: 728
Joined: Wed Nov 19, 2014 1:19 am
Blog: View Blog (0)

### Re: Problem with this line of code

try:
Code: Select all
`Math.pow(a, 2);`

In C++, C# and Java the operator for power isn't implemented.

ghost107
Poster

Posts: 321
Joined: Wed Jul 02, 2008 7:57 am
Blog: View Blog (0)