Adding numbers in Java?

0 Comments

For adding numbers of the same type we have to first define the variables. Like in the below code we define two variables of type int. 

int i=5;  
int j=10;

int sum = i + j;

System.out.println(sum);


For adding numbers which have different types; int i=5; float j=10;

float sum = i + j;

System.out.println(sum);

Sum variable type should be in float (data type)


Leave a Reply

Your email address will not be published.