Java Methods Homework Help
Previous
Java Methods:
In java method is a collection of statements it is used to perform some operation. Depends on user needs they create own method with argument or without argument and with return type or without return type.
Method creation:
Syntax:
Modifier returntype methodname( argumentlist)
{ ;
Body of the content
}
Example:
Public static void add( int a, int b ) { ; Int c; c= a+b; } ;
- Public, static – modifiers
- Void – return type (nothing return)
- Add – method name
- Int a, int b – argument list
Method calling:
There are two ways to call the method that is with return type or without return type.
Syntax;
If it have return type then
Datatype variable = methodname(arguments);
If no return type means
Methodname(arguments);
Passing parameters by value:
Example:
In this example using pass by value method will executed.
{`public class sample { ; public static void main(String[] args) { ; int x = 20; int y = 15; int z; // Invoke the method Z=add(x, y); System.out.println("addition value is :" + z); } ; public static int add(int x, int y) { ; // add x with y int a; a=x+y; return a; } ; } ; `}
Output
Addition value is : 35
Java Tutorials
- Environment setup
- Basic concept
- Object Classes
- Constructors
- OOPS in java
- data abstraction
- Variable Types
- Modifiers
- Operators
- Loop Controls
- Decision Making
- Strings
- Arrays
- Date and Time
- Methods in java
Java sample assignments
Programming Topics
- Ada
- Assembly Language
- AutoCAD
- BASIC
- Computer virus
- C Programming
- Euphoria
- Fortran Homework Help
- Game programming language
- Java Assignment Help
- JavaScript
- Java Servlets Help
- Machine Language
- Matlab
- Pascal
- Perl
- PHP
- Python
- Ruby
- Servlet Life Cycle
- Smalltalk
- SOAP
- Visual Basic
- COBOL
- Lisp
- Logo Help
- Plankalkul Help
- Prolog
- REBOL
- Rexx
- Scheme Help
- TCL
- ToonTalk Help