Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Java programming! ! The user inputs an integer n from the keyboard, and the program calculates the cumulative sum of n and outputs it. (For example: 1+2+3+4+...+N)
Java programming! ! The user inputs an integer n from the keyboard, and the program calculates the cumulative sum of n and outputs it. (For example: 1+2+3+4+...+N)
Import java.util.scanner;

Sum of public categories {

Public static void main(String[] args) {

Scanner s = new scanner (system. in);

int a = s . nextint();

int sum = 0;

sum = a *(a+ 1)/2;

system . out . println(sum);

}

}