Results 1 to 3 of 3
- 09-29-2011, 07:55 PM #1
Member
- Join Date
- Sep 2011
- Location
- Canada
- Posts
- 1
- Rep Power
- 0
New to Java - need help with adding many integers with rules such as ...
Hi everyone,
The teacher last class was blocking the entire board while speaking so I could not understand the logic be behind where to place certain parts of the code. I will ask him many questions this evening but I need your help please. I was asked to write a basic program with mathematical expressions so I wrote the following:
_____________________________________
public class Assign01 {
public static void main(String[] args) {
int num1=0,num2=0,sumvalue=0,diffvalue=0,productvalue= 0,quotvalue=0,remaindervalue=0;
Scanner sc = new Scanner(System.in);
System.out.println("Please choose your first number: ");
num1 = sc.nextInt();
System.out.println("Please choose your second number: ");
num2 = sc.nextInt();
sumvalue = num1+num2;
diffvalue = num1-num2;
productvalue = num1*num2;
quotvalue = num1/num2;
remaindervalue = num1%num2
_____________________________________
Under this I wrote "System.out.println ..." to write the answers and explain tips about math.
Can someone explain where can I add something like this?
______________________
int subtract(){
int result;
if (num1 > num2)
result = num1-num2;
else
result = num2-num1;
return result;
______________________
and something like this for division: "divide = if 15 divided by 0 = zero then return the value 0 as a result".
Any help/guidance would be greatly appreciated.
Regards,
MartinRRLast edited by MartinRR; 09-29-2011 at 07:59 PM.
- 09-29-2011, 08:48 PM #2
Re: New to Java - need help with adding many integers with rules such as ...
The method println() will print a line on the console.
System is a class you can read about in the API doc: Java Platform SE 6
Look in the list on the lower left for System. Click it and the doc will be in the right hand frame.
When you read the System class's doc you will see a Field named out.
out is an instance of the PrintStream class.
println() in a member of that class.
To see what this statement does, add some to your code at different places.
Add this following the line where you compute the sum:
System.out.println("sum value=" + sumvalue); // display the sum
- 09-29-2011, 09:05 PM #3
Re: New to Java - need help with adding many integers with rules such as ...
Cross posted at New to Java : Need help with my integers rules
Similar Threads
-
adding integers of an array
By Lene90 in forum New To JavaReplies: 9Last Post: 05-08-2011, 01:12 PM -
Count number of integers left in a file, hard with rules allowed!
By YeeP in forum New To JavaReplies: 5Last Post: 12-06-2010, 01:43 AM -
adding integers in JTable
By khanzaman in forum AWT / SwingReplies: 2Last Post: 06-14-2010, 10:12 PM -
Adding new rules in PMD eclipse plugin
By karuna in forum EclipseReplies: 1Last Post: 09-28-2008, 04:29 PM -
any can help me? About MDAS and PEMDAS rules and Infix-Prefix, Infix-Postfix rules
By darlineth in forum New To JavaReplies: 1Last Post: 07-05-2008, 04:08 PM
Bookmarks