+ 2

how can i work with two parameters in a methode ?

2nd Oct 2016, 10:36 AM
Aladin Khénissi
Aladin Khénissi - avatar
5 ответов
+ 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); } }
2nd Oct 2016, 1:55 PM
Evgeniy Krasnyanskiy
Evgeniy Krasnyanskiy - avatar
+ 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; } }
2nd Oct 2016, 11:24 AM
chetan acharya
chetan acharya - avatar
+ 1
thanks !
2nd Oct 2016, 12:05 PM
Aladin Khénissi
Aladin Khénissi - avatar
+ 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); } }
3rd Oct 2016, 2:26 PM
Taleb
Taleb - avatar
+ 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");
3rd Oct 2016, 5:17 PM
Ankur Sharma
Ankur Sharma - avatar