33 Program on static variable and method in Java

Code:

import java.util.Scanner;

class Static
{
public static void main( String args[] )
{

Static.add();
}

static int a,b;

static void add()
{
Scanner s = new Scanner(System.in);
System.out.println(" Enter any two numbers: ");

a=s.nextInt();
b=s.nextInt();
System.out.println(" Addition: "+(a+b));
}

}


Output:  

Previous
Next Post »