Types Of Variables
Types Of Variables
import java.util.*;
class TypesOfVariables
{
int s; /**Instance Variable*/
static int x; /**Class Variable*/
Scanner sc=new Scanner(System.in); //Instance Scanner object
void square() //function prototype
{
int n; /**Local Variable*/
System.out.print("Enter Any Number: ");
n=sc.nextInt();
s=n*n;
System.out.println("The Square of "+n+" is :"+s);
}
void sum()
{
int a,b;//Local Variable
System.out.print("Enter First Number: ");
a=sc.nextInt();
System.out.print("Enter Second Number: ");
b=sc.nextInt();
s=a+b;
System.out.println("The Sum of "+a+" and "+b+" is :"+s);
}
public static void main()
{
int n; /**Local Variable */
TypesOfVariables ob=new TypesOfVariables();
ob.square();
System.out.println("The Square is "+ob.s);
ob.sum();
System.out.println("The Sum is "+ob.s);
}
}