+ 2
how can i work with two parameters in a methode ?
5 Réponses
+ 3
Another example:
class MyClass {
static void sayHello(String name, int ago) {
System.out.println("Hello " + name + "." + "You are " + ago + " years.");
}
public static void main(String[ ] args) {
sayHello("David", 10);
sayHello("Amy", 12);
}
}
+ 2
public class Myclass
{
public static void main(String args[])
{
int x=10 , y=5 , z;
z = add(x,y); //function call with two parameters
System.out.println("sum is "+z);
}
int add(int a, int b) //function definition
{ //a takes x and b takes y
int c;
c=a+b;
return c;
}
}
+ 1
thanks !
+ 1
public class myClass{
static int divider(int num1, int num2){
return num1/num2;
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("plz enter 2 number:");
int x = sc.nextInt();
int y = sc.nextInt();
int z = divider(x,y);
System.out.println("Answer is :"+z);
}
}
+ 1
no. of parameters doesn't matter but when u will call a method give that no. of parameters which u hv declared in the method()
eg:-
method(int a,int b,long c,String s);
method(1,2,5,"Ankur");