473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Running totals of variables in a loop.

Hey I am having trouble with loops the problem is as follows;
My program so far gets me to what I need which is the remainders which are the last digits of the 5 digit number inputted, I need a way for java to keep a running sum of all the remainders and then I need a new variable which is the sum of the remainders after going through the loop.
Any help is greatly appreciated.

mport java.util.Scanner;

public class Document1
{
public static void main(String[] args)
{

Scanner keyboard = new Scanner(System.in);

// Obtain initial data from user
System.out.print("Enter 5 digit Integer: ");
int n = keyboard.nextInt();
getRemainder(n);
System.out.println();
}

public static void getRemainder(int n)
{


for (int i = 1; i < 6; i++)
{
int remainders = n % 10;
n = n / 10;

System.out.println(remainders);
System.out.println(n);
System.out.println(" ");



}
int a = n;


System.out.println(a);
Mar 11 '10 #1
2 8157
jkmyoung
2,057 Expert 2GB
Please use [ code ] tags [ / code ] when posting .
When you say sum, do you mean string wise, or additive wise (sum of digits?)

Declare a at the top of your function, and set a += n inside your loop.
Mar 11 '10 #2
Ok, thank you I figured it out,
int total = 0
needs to be befor the loop and I needed to use the total inside the loop to keep a running total adding n to it each time.
Mar 11 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bill Dika | last post by:
Hi I am trying to calculate a running total of a calculated textbox (tbAtStandard) in GroupFooter1 for placement in a textbox (tbTotalAtStandard) on my report in Groupfooter0. The problem...
6
by: KashMarsh | last post by:
Trying to show running totals on a report, except it needs to show one total amount and values being subtracted from it. For example, the report shows a Total Inventory amount (TotInvAmt). And...
0
by: Beacher | last post by:
Hi all, I'm having troubles with a report I've created. You make some selections on a form which then sets a reports filter property and opens the report, this works fine. One bigger problem...
2
by: BerkshireGuy | last post by:
I have the following code: Dim strSQL As String Dim DB As DAO.Database Dim RS As DAO.Recordset Dim intNumOfPaid, intNumOfHypoed, intNumOfNotTaken, intNumOfDeclined, intNumOfWasted,...
5
by: the_jos | last post by:
Dear reader, I am trying some things with xml/xsl and cannot find a solution for what I would like to do. I have 2 base items with name and price and two that are composed of base two (given...
3
by: =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?= | last post by:
Hi, Fairly easy to create one running total for a gridview but what if you have dozens of them? I have a gridview that allows bulk editing (all rows at once) and have it set up so that, on data...
3
by: mochatrpl | last post by:
I am looking for a way to make a query / report display the running average for total dollars. I have already set up a query to provide totals dollars per day from which a report graphly shows...
9
by: JJM0926 | last post by:
I'm trying to create a running totals query in access 97. I have followed the directions on how to do it from Microsofts website article id 138911. I took their code they had and replaced it with...
6
by: Stuart Shay | last post by:
Hello All: I have a array which contains the totals for each month and from this array I want to get a running total for each month decimal month = new decimal; month = 254; (Jan) month =...
5
by: Spetman | last post by:
I’m having trouble using MS Access 2003 to accomplish something that I thought would be relatively easy: I’m trying to create a query that will give me the projected balance of an account (such as a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.