• 12-06-2011, 08:26 AM
thirdyberdejo
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 ...
• 12-06-2011, 02:02 PM
Norm
Quote:

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.
• 12-06-2011, 03:17 PM
Tolls
9 - 600 != 591
9 - 600 = -591.
• 12-06-2011, 05:43 PM
Dark
@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:
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.
• 12-06-2011, 06:37 PM
sunde887
If that is what you want it may be helpful to just use an absolute value method. Check the Math class.
• 12-07-2011, 09:40 AM
thirdyberdejo
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..
• 12-07-2011, 09:42 AM
thirdyberdejo
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..
• 12-07-2011, 10:43 AM
Tolls
No.
We don't do that sort of thing around here.
• 12-07-2011, 10:59 AM
thirdyberdejo
• 12-07-2011, 01:37 PM
Tolls
Write some code?
That tends to be how you learn.
• 12-07-2011, 01:38 PM
Norm
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-08-2011, 03:08 AM
thirdyberdejo
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..
• 12-08-2011, 03:18 AM
Norm
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
• 12-08-2011, 03:43 AM
Junky
Quote:

Originally Posted by thirdyberdejo

• 12-08-2011, 03:47 AM
Norm
I get the feeling this OP is trying to figure out how to write any program even the HelloWorld program.
• 12-08-2011, 04:06 AM
sunde887
```public class Hello{   public static void main(String[] args){     System.out.println("Hello, World!");   } }```