Java: Java Programming For Beginners a simple Start To Java Programming (Written By a software Engineer)


Download 0.82 Mb.
Pdf ko'rish
bet55/95
Sana09.01.2022
Hajmi0.82 Mb.
#261112
1   ...   51   52   53   54   55   56   57   58   ...   95
Bog'liq
Java Programming For Beginners - A Simple Start to Java Programming ( PDFDrive )

Variable Arguments(var-args)
Java  Development  Kit  1.5  empowers  you  to  pass  arguments,  which  can  be  of  variable
number. However, the data type of the parameters should be the same. The parameter in
the system is declared in the following manner:
typename… nameofparameter
In the statement, you define the data type emulated by an ellipsis (…). Only one variable-
length  parameter  may  be  determined  in  a  method,  and  this  parameter  must  be  the  last
parameter. Any customary parameters must go before it.
Sample Implementation:
public class Mysampleclass {
public static void main(string args[]) {
printmaxval(33, 45, 43, 22, 5);
printmaxval(new double[]{5, 8, 1});
}
public static void printmaxval( double… mynum) {
if (mynum.length == 0) {
System.out.println(“No Arguments!”);
return;


}
double resultant = mynum [0];
for (int x = 1; x < mynum.length; x++)
if (mynum[x] > resultant) resultant = mynum[x];
System.out.println(“Max val = ” + resultant); }
This would deliver the accompanying result:
Max val = 45.0
Max val = 1.0

Download 0.82 Mb.

Do'stlaringiz bilan baham:
1   ...   51   52   53   54   55   56   57   58   ...   95




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling