Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Notas de lectura

Class notes | Methods | Intro to Computer Programming (COMP150) Introduction to Java Programming and Data Structures, ISBN: 9780134670942

Puntuación
-
Vendido
1
Páginas
5
Subido en
09-10-2022
Escrito en
2022/2023

Typed Notes on Java Methods, including standard code forms and sample code blocks

Institución
Grado

Vista previa del contenido

Methods
Date @October 7, 2022

Introduction to Java Programming and Data Structures, Comprehensive
Text Version: Chapter 6


Defining Methods
A method is a collection of statements that are grouped together to perform an
operation


// define the method
public static int max(int num1, int num2) {
int result;
if (num1>num2) {
result = num1;
} else {
result = num2
}
return result;
}

// invoke the method
int z = max(x, y);




public static int max(int num1, int num2) - method header

public static - modifier
int - returnValueType

the data type of the value that is returned by the method

if the method does not return a value, the returnValueType is the keyword void

max - method name
(int num1, int num2) - method signature

combination of the method name and the parameter list

int num1, int num2 - parameter list



Methods 1

, num1 & num2 - formal parameters

variables defined in the method header

return result; - return value
x & y - actual parameters (arguments)

the value passed on to the parameter when a method is invoked

Calling Methods

// define the method
public static int max(int num1, int num2) {
int result;
if (num1>num2) {
result = num1;
} else {
result = num2
}
return result;
}

public static void main (String[] args) {
int i = 5;
int j = 2;
int k = max(i, j)

System.out.println("The maximum between " + i + " and " + j + " is " + k);
}




this program takes the integer values of i and j and puts them through the max

method,


caution:


// section a
public static int sign(int n) {
if (n > 0) {
return 1;
} else if (n == 0) {
return 0;
} else if (n < 0) {
return -1;
}
}




Methods 2

Libro relacionado

Escuela, estudio y materia

Institución
Estudio
Grado

Información del documento

Subido en
9 de octubre de 2022
Número de páginas
5
Escrito en
2022/2023
Tipo
NOTAS DE LECTURA
Profesor(es)
Stephen chiong
Contiene
Week 5

Temas

$8.49
Accede al documento completo:

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Conoce al vendedor
Seller avatar
dazyskiies

Conoce al vendedor

Seller avatar
dazyskiies university of the fraser valley
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
1
Miembro desde
4 año
Número de seguidores
0
Documentos
27
Última venta
3 año hace

0.0

0 reseñas

5
0
4
0
3
0
2
0
1
0

Documentos populares

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes