Definitions of constants in Java
public class first{
static final int year=365; Declaring a constant
public static void Main (string[] args){
System.out.println ("Two years equals" +2*year+ "Day");
}
}
Definition of variables in Java
public class testjavaintchar{
public static void Main (string[] args){
int num=3; Declares an integer variable num with a value of 3
Char ch= ' x '; Declares a character variable ch, assigned to X
System.out.println (num+ "is an integer!) "); The value of the output num
System.out.println (ch+ "is a character! "); Value of Output ch
}
}
Definition of variables in Java
public class Testmemvar {
static int a=1; Define a member variable
public static void Main (string[] args) {
System.out.println ("The value of the member variable is" +a);
}
}
Where local variables are used in Java
public class Jubudemo {
public static void Main (string[] args) {
int sum=0;
for (int i=1;i<=5;i++)//define local variable I
{sum=sum+i;
System.out.println ("i=" +i+ ", sum=" +sum);
}
}
}
Learning about constants and variables (Java)