The following program is used to calculate the sum of two numbers using a static method.
public class Sum { //declaration of variables static int value1,value2,sum; static Scanner read=new Scanner(System.in); //method to add public static void add(int v1, int v2) { System.out.println("Sum="+(v1+v2)); } //main method public static void main(String args[]) { //input values System.out.println("Enter the first value=>"); int x=read.nextInt(); System.out.println("Enter the second value=>"); int y=read.nextInt(); //call the method add add(x,y); } }
good luck
