| | |
Parameters order
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
What do you want to know about parameters? They're basically variables set up in the method declaration that allow you to pass values to the method. If your method is to return something, you would need a return statement. I.e. your method should look like this
public static int difference(int num1, int num2){
return num1 - num2;
}
Andy
public static int difference(int num1, int num2){
return num1 - num2;
}
Andy
Nobody believes the official spokesman, but everybody trusts an unidentified source.
-- Please do not PM me with questions about a thread. If you respond to a thread, then everyone can benefit.
-- Please do not PM me with questions about a thread. If you respond to a thread, then everyone can benefit.
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
•
•
•
•
Originally Posted by nicentral
What do you want to know about parameters? They're basically variables set up in the method declaration that allow you to pass values to the method. If your method is to return something, you would need a return statement. I.e. your method should look like this
public static int difference(int num1, int num2){
return num1 - num2;
}
Andy
to call that method you would do this:
int firstNum = 35;
int secondNum = 5;
ClassName.difference(firstNum,secondNum);
you always want the largest minus the smallest, here is two ways of doing just that so you don't have to worry or know the order...
I think that was what you were asking. the difference method is too intuitive so I created a second called subtract with an if statment in there which is hopefully easier to understand
Java Syntax (Toggle Plain Text)
public class Test { public static void main(String[] args) { int n1 = 10; int n2 = 4; System.out.println(difference(n1,n2)); System.out.println(difference(n2,n1)); System.out.println(difference(n1,n2)); System.out.println(difference(n2,n1)); } public static int difference(int num1, int num2) { return num1 > num2 ? num1-num2 : num2-num1; } public static int subtract(int num1, int num2) { int returnVal; if (num1 > num2) { returnVal = num1 - num2; } else { returnVal = num2 - num1; } return returnVal; } }
I think that was what you were asking. the difference method is too intuitive so I created a second called subtract with an if statment in there which is hopefully easier to understand
![]() |
Similar Threads
- C# VS 2005 - SQL Query Parameters to an ODBC DataSource (C#)
- Internet Explorer-OUT OF ORDER + More (Viruses, Spyware and other Nasties)
- DOS C++, pulling boot order and hard drive parameters, (C++)
Other Threads in the Java Forum
- Previous Thread: Offline browsing web site technology?
- Next Thread: Listeners
| Thread Tools | Search this Thread |
actuate android api applet application applications array arrays automation balls bank binary bluetooth business chat class classes clear client code codesnippet collections component database defaultmethod development dice dragging ebook eclipse error event exception formatingtextintooltipjava fractal froglogic game givemetehcodez graphics gui hql html ide image infinite input integer intersect invokingapacheantprogrammatically j2me java javaprojects jni jpanel julia linux list loop looping map method methods mobile mysql netbeans newbie numbers openjavafx parameter php print problem program programming project recursion repositories scanner screen scrollbar server set size sms sort sorting sql sqlserver state storm string sun superclass swing swt text-file threads time tree windows






