answersLogoWhite

0


Best Answer

In Java:

You declare the variable like this:

int sum;

If you want to include decimals, change this to:

double sum;

To store an initial value, just use the assignment operator:

sum = 0;

You can combine this with the declaration:

double sum = 0.0;

To add something to the variable, for example the value of a variable called "x", use one of the following:

sum = sum + x;
sum += x;

In Java:

You declare the variable like this:

int sum;

If you want to include decimals, change this to:

double sum;

To store an initial value, just use the assignment operator:

sum = 0;

You can combine this with the declaration:

double sum = 0.0;

To add something to the variable, for example the value of a variable called "x", use one of the following:

sum = sum + x;
sum += x;

In Java:

You declare the variable like this:

int sum;

If you want to include decimals, change this to:

double sum;

To store an initial value, just use the assignment operator:

sum = 0;

You can combine this with the declaration:

double sum = 0.0;

To add something to the variable, for example the value of a variable called "x", use one of the following:

sum = sum + x;
sum += x;

In Java:

You declare the variable like this:

int sum;

If you want to include decimals, change this to:

double sum;

To store an initial value, just use the assignment operator:

sum = 0;

You can combine this with the declaration:

double sum = 0.0;

To add something to the variable, for example the value of a variable called "x", use one of the following:

sum = sum + x;
sum += x;

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

In Java:

You declare the variable like this:

int sum;

If you want to include decimals, change this to:

double sum;

To store an initial value, just use the assignment operator:

sum = 0;

You can combine this with the declaration:

double sum = 0.0;

To add something to the variable, for example the value of a variable called "x", use one of the following:

sum = sum + x;
sum += x;

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How to Declare a variable that stores the cumulative sum java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is out of scope in returning objects in java?

if u declare variable in method & tray to use this variable outside the method then it is out of scope


Which qualifier is used to declare read-only variable in java?

A variable declared as final can't be modified, once a value is assigned.


How do you return an object in java?

With the command return, followed by an object variable. In the method header, you have to declare the return type as the class of the object.


How do youdeclare a variable in jsp?

You declare a variable the same in a JSP as you do in a servlet. Let's say you want to declare a String variable called "foo" and you wanted to assign it a value of "bar." You would do this: String foo = "bar"; Of course, in a JSP, any Java code needs to be enclosed within <% and %>.


What is native variable in java?

native is a key word used in java method. there is no variable as native in java


How you make shared and synchronized variable in java thread?

A Variable that is shared as well as synchronized cannot be created in Java. These two terms are mutually exclusive and a variable that is synchronized in java cannot be shared and vice versa


What is the syntax of global variable in java?

There's no global variables in Java.


What are static objects in java?

There is no separate entity as a static object in java. The static keyword in java is used to signify that the member (either a variable or a method) is not associated to an object instance of the class. It signifies the fact that the member belongs to the class as a whole. The words static and objects are opposites of one another so you cannot have a static object. However, you can declare an object as a class level variable which could be referred to as a static object but it will be referred to as a static or class variable and not a static object.


What is a variable type in Java?

int


Can you define variables in interface in java?

yes we can define a variable in an interface in java.


What is the code required to convert an integer variable to a string variable in Java?

There are several different methods to convert an integer variable to a string variable in Java. For example, one can use the following code to convert an integer variable to a string variable: Integer.toString(number)


How do you equate a php variable to a javascript variable?

Ideal thing would be to retrieve the value from PHP using AJAX and then assigning it to a java script variable. Thereafter compare it to the java script variable that is already present.