Program to add two numbers using function in java.
import java.util.*;
public class function {
public static int calculateSum(int a,int b){
int sum=a+b;
return sum;
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.print("enter two numbers=");
int a=sc.nextInt();
int b=sc.nextInt();
int s=calculateSum(a,b);
System.out.print("the sum of two number is="+s);
}
}
■》Output->
enter two numbers=
3
4
the sum of two number is= 7
Comments
Post a Comment