3 Replies - 252 Views - Last Post: 05 December 2011 - 04:40 PM Rate Topic: -----

#1 Trevor1001  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1817
  • View blog
  • Posts: 4,625
  • 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
Was This Post Helpful? 0
  • +
  • -

#3 Trevor1001  Icon User is offline

  • New D.I.C Head

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

Re: Java Maths Program

Posted 05 December 2011 - 04:35 PM

View Postsmohd, 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?
Was This Post Helpful? 0
  • +
  • -

#4 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1817
  • View blog
  • Posts: 4,625
  • 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?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1