answersLogoWhite

0

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

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

RossRoss
Every question is just a happy little opportunity.
Chat with Ross
JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
More answers

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

15y ago
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