Ask your own question, for FREE!
Computer Science 12 Online
OpenStudy (anonymous):

I Need help writing a small java program... This is what it's suppose to do 1.Write a program that prints sum and average of the numbers from 1 to 100. Use for loop to generate numbers from 1 to 100.

OpenStudy (kva1992):

int sum= 0; int average = 0; for (int i=0 ; i<101 ; i++){ sum= sum+ 1; average = sum/i; } that should do it so essentially this is what im doing: 1. declaring sum as an integer and giving it a value of 0 2. declaring average as an integer and giving it a value of 0 3. creating a for loop which in the processes you declare the integer i and assign the value as 0 then make a condition as long as i is less then 101 increment i by 1 4.setting the value of sum equal to the value of sum +1 so an example is sum = 1 then its 1 plus 1 and 2 plus 1 and so on. 5. giving average a value of sum divided by i meaning your dividing the sum by the number of times you have added which is your average formula. 6. if you need to print this to a console then all you would do is add System.out.println("sum= " + sum + "\naverage=" + average); System.out.println("sum= " + sum + System.lineSeparator + "average=" + average); Also System.out isnt needed if you already imported that properly if you did then all you would have to call is println("and whatever you want to print here")

rebeccaxhawaii (rebeccaxhawaii):

\(\Huge\boxed{\boxed{\boxed{\huge\mathbb{WELCOME~TO~OPENSTUDY} }}}\) Hey i have made this to hopefully answer any questions you may have. But if it doesn't feel free to pm me c: http://openstudy.com/users/rebeccaxhawaii#/updates/56f5205ce4b07a8c82287f75 Good Luck with your studies! \(\Huge\heartsuit\)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!