1. Member
Join Date
Dec 2011
Posts
6
Rep Power
0

how to add and subtract in java program

example: 9 - 600 = 591 ....... if the input is 9 the 600 is automatically subtract and the output is 591 ...
Last edited by thirdyberdejo; 12-06-2011 at 08:36 AM.

how to add and subtract in java program
You could use an expression in an assignment statement to add and/or subtract. An expression is two operands with an operator between them and perhaps surrounded by ()s: 44+2 or 7-3
Post the code you are working on so we can see your problems.
Also post the full text of any error messages.

3. Moderator
Join Date
Apr 2009
Posts
13,541
Rep Power
27

9 - 600 != 591
9 - 600 = -591.

@Tolls, I believe the OP wants to know how to make it so the smaller number is automatically subtracted from the larger. So if the two inputs were 9 and 600, the output would be 591.

@OP, if I assume correctly, you will need to get the two inputs. Then you will need to compare them in an if, ie:
Java Code:
```if (a>b) {//Subtract b from a}
else {//Subtract a from b}```
Do you have any code to show us? That might help us clarify a little better.

If that is what you want it may be helpful to just use an absolute value method. Check the Math class.

6. Member
Join Date
Dec 2011
Posts
6
Rep Power
0

i dont have no codes to show you...because i'm a beginner and i need the full codes...can you help for this?... please help me..

7. Member
Join Date
Dec 2011
Posts
6
Rep Power
0

I dont have codes to show you...because i'm a beginner and i need the full codes...can you help for this?... please help me..

8. Moderator
Join Date
Apr 2009
Posts
13,541
Rep Power
27

No.
We don't do that sort of thing around here.

9. Member
Join Date
Dec 2011
Posts
6
Rep Power
0

10. Moderator
Join Date
Apr 2009
Posts
13,541
Rep Power
27

Write some code?
That tends to be how you learn.

What is the purpose of your request for help?
Do you want to learn how to program in java?
Or do you want some code you can hand in to your professor?

12. Member
Join Date
Dec 2011
Posts
6
Rep Power
0

yes i want to learn about java program..my problems is i want to create an timecard in using java program and i don't know how i start..

I guess you should read some tutorials about how to program in java.
I don't have any links to really basic tutorials. Here are some I have:
The Java™ Tutorials
The Really Big Index

Originally Posted by thirdyberdejo

I get the feeling this OP is trying to figure out how to write any program even the HelloWorld program.

If it is HelloWorld, I'll gladly write it for him:

Java Code:
```public class Hello{
public static void main(String[] args){
System.out.println("Hello, World!");
}
}```

17. Member
Join Date
Dec 2011
Posts
6
Rep Power
0

can u help me for javascript?

Try a javascript forum for help with javascript problems.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•