Number Literals or Integer Literals in Java Programming

Number Literals or Integer Literals in Java Programming

Previous Home Next

 

Number or Integer literals are used to include whole number valuesin programs, to be used for calculations and outputs.  
Java integers are stored internally as binary numbers, but can appear in source programs as ordinary decimals.

There are some rules for defining integer literals in java. following are the rules to be followed while writing java  integer literals:

* Java integer literals are by default constant of int type

*Java integer literals can be sequences of decimal digits, optionally preceded by a minus sign for negative integers.
e.g.15
      -1253

*Java integer literals cannot contain any blanks or commas.
 e.g 45 12 // error occurs no space between integers
      45,12 // no comma between the numbers

*There should be no blank space between the minus sign (-) and the number for negative integers.

e.g - 1253 // error occurs no space between - sign and number

 


 
public class Integer
{
public static void main (String [] arg)
{
int Count;
System.out.print ("Java Integer Examples:\n");
Count = 35;
System.out.println ("Count has a value of " + Count);
Count = -12536;
System.out.println ("Count has a value of " + Count);
Count = 5698;
System.out.println ("Count has a value of " + Count);


Previous Home Next