Sum of 10 numbers Display the sum of numbers from 1 to 10 line by line (there should be 10 lines):

1 1+2=3 1+2+3=6 1+2+3+4=10 ... 

Example output:

 1 3 6 10 

Here is a sample code, I do not know what to do next ...

 public static void main(String[] args) { for(int a = 1; a <= 10; a++){ System.out.println(a); } } 

Closed due to the fact that the essence of the question is incomprehensible by the participants Vladimir Martyanov , pavlofff , D-side , Alexey Shimansky , Nicolas Chabanovsky Jun 3 '16 at 9:44 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Give the parts of the code in which you tried to solve this problem. - Alexander
  • one
    What are you having problems with? provide a piece of code. It is not decided to decide for a person, it is decided to help. - Denis
  • public static void main (String [] args) {for (int a = 1; a <= 10; a ++) {System.out.println (a); }} - user212022
  • 1,3,6,10 and incrementing - user212022
  • I don't understand how to set a floating difference - user212022

1 answer 1

You just have to memorize the amount and add the following number to it each time:

 public static void main(String[] args) { Integer sum = 0; for(int i = 1; i <= 10; i++) { sum = sum + i; System.out.println(sum); } } 

Conclusion : http://ideone.com/hhU29F

enter image description here

  • Thank you very much. I also thought that the current put this variable sum in the for block and with each cycle the initial value was returned - user212022
  • ter will know - user212022
  • @ user212022 if you were given the correct answer, tick it as correct for those who later come across this question. - Denis