Pages

Wednesday, September 4, 2019

what is integer in java?

what is integer ?

Integer :  integer is whole number of positive,Negative and Zero.

example : positive integer numbers = 1,2,3,4,5
                 Negative integer numbers = -1,-2,-3,-4,-5
                 Zero = 0.

How to use integer in java ?

In java we can use at least one class in a program and that class it's contain many methods or Main method.In java we can declare variables in class or in methods if we can declare variable in class than it's a global variable or we can declare in method than it's a local variable.Integer is declare in any type of variable that depends your program.


Syntax:
           
int name=value;

In above syntax replace value of int is whole integers positive,negative or zero.

Step:1 - Declare int in class or particular method in program.

Here, we can declare int in main method.


here,we can use three int for simple addition of numbers.
assign value of int a,b is 10,10 and In integer c we can store the ans of addition.

Step:2 - Addition of a and b and store ans in c.

c=a+b;

Step:3 -  simple print c value using (System.out.println()).

System.out.print("sum of number is:"+c);

example:



Output:


what is an integer in java?

so,this way to use integer in java.


Share:

0 Comments:

Post a Comment