Java - Sum integer till a value using while loop

Description

Sum integer till a value using while loop

Demo

import java.util.Scanner;

public class SumAll {

     public static void main(String[] args) {
          Scanner input = new Scanner(System.in);

          System.out.print("Please enter the max number:");

          int max = input.nextInt();
          int i = 0;
          int sum = 0;
          while ( i <= max) {
               System.out.println("Number " + i);
               sum += i;//from w  w  w.  j a v  a2  s.c o m
               i++;
          }
          System.out.println("Sum of All is " + sum);
     }
}

Related Topic