# Java Maths Program

Page 1 of 1

## 3 Replies - 385 Views - Last Post: 05 December 2011 - 04:40 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=258603&amp;s=3e14628441c8737244fb079efd6203c7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Trevor1001

Reputation: 0
• Posts: 6
• Joined: 04-December 11

# Java Maths Program

Posted 05 December 2011 - 03:56 PM

I'm having an issue with a small java program that I have written:
```double coords[]={500, 750};
double vline[]={1, 1};

double a = coords[0] + coords[1];
double b = vline[0] + vline[1];
double c = a / b;
double d = c - coords[0];
double d1 = c - coords[1];
double e = c - d1;
double e1 = c - d;

System.out.println(e);
System.out.println(e1);
```

The two arrays at the top with the current values print out the following result e = 750.0, e1 = 500.0. However if I change the values in the vline array to for example "int vline[]={2, 1};" I should get the results e = 333.3333333333333, e1 = 83.33333333333331, but I don't I get the results e = 750.0, e1 = 500.0.

Is This A Good Question/Topic? 0

## Replies To: Java Maths Program

### #2 smohd

• Critical Section

Reputation: 1820
• Posts: 4,627
• Joined: 14-March 10

## Re: Java Maths Program

Posted 05 December 2011 - 04:22 PM

Are you sure with your calculations? look at this peace of code:
```        double d = c - coords[0];
double d1 = c - coords[1];
double e = c - d1;
double e1 = c - d;
```

It is simply showing that e = coords[1] and e1 = coords[0].
Proof:

Quote

d = c - coords[0] -------- (i)

And
e1 = c - d -------(ii)
Replace d by value from eq(i) and we get:
e1 = c - (c - coords[0])
e1 = c - c + coords[0]
.: e1 = coords[0]

And the same case for e, so no matter what values are in vline, you will get the same result for e and e1 according to your formulae

### #3 Trevor1001

Reputation: 0
• Posts: 6
• Joined: 04-December 11

## Re: Java Maths Program

Posted 05 December 2011 - 04:35 PM

smohd, on 05 December 2011 - 04:22 PM, said:

Are you sure with your calculations? look at this peace of code:
```        double d = c - coords[0];
double d1 = c - coords[1];
double e = c - d1;
double e1 = c - d;
```

It is simply showing that e = coords[1] and e1 = coords[0].
Proof:

Quote

d = c - coords[0] -------- (i)

And
e1 = c - d -------(ii)
Replace d by value from eq(i) and we get:
e1 = c - (c - coords[0])
e1 = c - c + coords[0]
.: e1 = coords[0]

And the same case for e, so no matter what values are in vline, you will get the same result for e and e1 according to your formulae

So how would I go about changing my code?

### #4 smohd

• Critical Section

Reputation: 1820
• Posts: 4,627
• Joined: 14-March 10

## Re: Java Maths Program

Posted 05 December 2011 - 04:40 PM

Quote

So how would I go about changing my code?

to do what? do you have any formula which you are implementing? or what thing are you trying to achieve?