473,465 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Running totals of variables in a loop.

2 New Member
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 8160
jkmyoung
2,057 Recognized Expert Top Contributor
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
krzemienski
2 New Member
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.