Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Does anyone have a solution to this problem???
Closed Thread
Old 10-20-2004, 02:20 PM   #1 (permalink)
 
Newb Techie

Join Date: Oct 2004

Posts: 14

LauraP

Default Does anyone have a solution to this problem???

Help with JAVA coding

...If you have a function as follows:
int fun(int *k)
{
*k +=4;
return 3*(*k)-1;
}
...and if fun is used in the program below:
void main()
{
int i = 10;
int j = 10;
int sum1;
int sum2;

sum1 = (i/2)+ fun(&i);
sum2 = fun(&j) + (j/2);
}
...what is the values of sum1 and sum2 if the operands in the expressions are
looked at from left to right and right to left?

Could someone please help me with this question? I would highly appreciate it

Thanks!
LauraP is offline  
Old 10-20-2004, 02:53 PM   #2 (permalink)
 
Newb Techie

Join Date: Oct 2004

Posts: 28

Garry

Default

sum1 = 46
sum2 = 48
Garry is offline  
Old 10-23-2004, 04:15 PM   #3 (permalink)
 
Super Techie

Join Date: Jun 2004

Posts: 312

sippin codeine

Send a message via Yahoo to sippin codeine
Default

Try Delphi
__________________
**[System specs]**

Delphi Enterprise 6 - 7
VB 6.0 - 2005 EE
sippin codeine is offline  
Old 10-23-2004, 08:14 PM   #4 (permalink)
 
Ultra Techie

Join Date: Sep 2003

Location: Bamberg, Germany

Posts: 549

Iron_Cross

Send a message via ICQ to Iron_Cross Send a message via MSN to Iron_Cross Send a message via Yahoo to Iron_Cross
Default

Why try delphi? Personally if I were going to switch languages from Java, I'd go with C#. Which much higher marketability than Delphi, as well as (I believe) more usefulness.
__________________

See today\'s Penny-Arcade!(May contain foul lanuage)
Pain is weakness leaving the body.

PM Me for my MSN
Iron_Cross is offline  
Old 10-24-2004, 04:57 AM   #5 (permalink)
 
Super Techie

Join Date: Jun 2004

Posts: 312

sippin codeine

Send a message via Yahoo to sippin codeine
Default

Delphi and c# are basically the same, they were designed by the same person, Anders Hejlsberg; Only difference is Delphi is easier to use and the syntax is cleaner, both are OOP.

Delphi Code
Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
if Sender is TButton then
begin
(Sender as TButton).Caption := 'Hello';
end;
end;
C# Code
Code:
private void button1_Click(object sender, System.EventArgs e)
{
if (sender is Button)
{
(sender as Button).Text = "Hello";
}
}

__________________
**[System specs]**

Delphi Enterprise 6 - 7
VB 6.0 - 2005 EE
sippin codeine is offline  
Old 10-24-2004, 02:38 PM   #6 (permalink)
 
Ultra Techie

Join Date: Sep 2003

Location: Bamberg, Germany

Posts: 549

Iron_Cross

Send a message via ICQ to Iron_Cross Send a message via MSN to Iron_Cross Send a message via Yahoo to Iron_Cross
Default

Exactly, C# is more structured, and therefor more powerful. Personally I'd change your example to:
Code:
private void button1_Click(object sender, System.EventArgs e)
{
    Button b = (Button)sender;
    b.Text = "Hello!";
}
Much simpler All that extra stuff isn't needed.
__________________

See today\'s Penny-Arcade!(May contain foul lanuage)
Pain is weakness leaving the body.

PM Me for my MSN
Iron_Cross is offline  
Old 10-24-2004, 05:16 PM   #7 (permalink)
 
Super Techie

Join Date: Jun 2004

Posts: 312

sippin codeine

Send a message via Yahoo to sippin codeine
Default

That code was just to point out the similarities, but tell me, how do you create a form in c# , i've always wanted to know, in Delphi you just drag and drop your controls/ buttons onto the default form that opens when you start the IDE.
__________________
**[System specs]**

Delphi Enterprise 6 - 7
VB 6.0 - 2005 EE
sippin codeine is offline  
Old 10-24-2004, 10:46 PM   #8 (permalink)
 
Super Techie

Join Date: Jun 2004

Posts: 348

sithspawn

Default

Looking at this from a mathematical point of view...

sum1 = (i/2)+ fun(&i);
sum2 = fun(&j) + (j/2);

if i and j are both equal to 10 these equations are exactly the same??

i got 46 for both, im not sure where 48 comes from??
sithspawn is offline  
Old 10-25-2004, 09:53 PM   #9 (permalink)
 
Ultra Techie

Join Date: Sep 2003

Location: Bamberg, Germany

Posts: 549

Iron_Cross

Send a message via ICQ to Iron_Cross Send a message via MSN to Iron_Cross Send a message via Yahoo to Iron_Cross
Default

To create a form you can either use the IDE or just do this...

Code:
using System;
using System.Windows.Forms;

public class TestForm : Form {
    public static void Main(string[] args){
        Application.Run(new TestForm());
    }
}
And of course adding controls is longer, but that's a basic form.
__________________

See today\'s Penny-Arcade!(May contain foul lanuage)
Pain is weakness leaving the body.

PM Me for my MSN
Iron_Cross is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On