473,396 Members | 1,608 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,396 software developers and data experts.

Sums

JAVA for Windows XP

the question is:

Write an application that shows the sum of 1 to n for every n from 1 to 50. That is, the program prints 1 (the sum of 1 alone), 3 (the sum of 1 and 2), 6 (the sum of 1, 2, and 3), and so on.

I'm not looking for a answer, just some ideas on where to start. I was able to create an application that sums the integers from 1 to 50 and displays the answer 1275, but I'm not sure how to go about writing an app that shows the sum for every n.

thanks for any help.
Nov 6 '07 #1
3 3194
epots9
1,351 Expert 1GB
please provide the section of code you are having trouble with.
Nov 6 '07 #2
Well like I said, the only code I have is for the app that sums from 1 to 50. So here it is.

Expand|Select|Wrap|Line Numbers
  1. public class Sum50
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         int start = 0;
  6.         int sum = 0;
  7.  
  8.         while (start < 50)
  9.         {
  10.             ++start;
  11.             sum = sum + start;
  12.         }
  13.         System.out.println("The sum of 1 to 50 is " + sum);
  14.     }
  15. }
  16.  
Nov 6 '07 #3
Laharl
849 Expert 512MB
To print out every partial sum, simply add a print statement in your while loop. Think about it what needs to be printed, and if you're still having trouble, post again and we'll help you.
Nov 7 '07 #4

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

Similar topics

2
by: guyzdancin | last post by:
I have developed a parsing program to handle large csv files and compute sums. The program was developed and successfully tested using only String objects. I want replace String objects with ...
1
by: Hunter Hillegas | last post by:
I have just added a third table to a query and I am no longer getting the results I am expecting. Three Tables: CUSTINVOICEJOUR (Header Table) CUSTINVOICETRANS (Line Item Table) MARKUPTRANS...
9
by: rinmanb70 | last post by:
I have a table of transactions, some with past dates, some dated the current date, and some dated in the near future. On a report, I'm looking for a way to get four different sums using the...
8
by: DrewKull | last post by:
Hello, I have a query which sums check boxes (so 0 or -1) then Abs the sum so i can get the number of check box 'checked' per column... based on start and end date. SELECT Abs(Sum(CommCon)) AS ,...
3
by: tpdinh | last post by:
I have to evaluate the sum in the for-loop. How do i do that? Also, I need to print the partial sums using %e. Please help!
5
chunk1978
by: chunk1978 | last post by:
hey... can anyone show me how to calculate sums to the 2nd decimal only? like: 5.50 + 4.00 = 9.50 i seriously have zero idea and could defo use some help...thanks! <script...
8
by: RJMac | last post by:
I’m using ADO 2.6 in VB6 to read in data from a Union query (qryJoinBalanceData) in Access 2000. The Union query contains 3 sub-queries, each of which joins several tables, but they all generate...
1
by: wisemen | last post by:
I have a table with 2 columns, and .I want to run a query that will give me a cumulative sum of the no. of entries that have an <= and on the second column give me a cumulative sum of the no. of...
1
by: someusernamehere | last post by:
Hey people, I need to do some sistem in PHP and MySQL, I have do it a part but the other is the problem, basically is mathemetical operations, te user register something and after insert some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.